Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

下载语料的文件名没有格式后缀 #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# maven
chatbotv1/target/

# py
__pycache__/
*.pyc

# vim
*.swp
*.swo

# idea
*.iml
*.ipr
*.iws
.idea/

# tmp files
subtitle/subtitle_crawler/result/
16 changes: 16 additions & 0 deletions subtitle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 爬取字幕语料

* 依赖curl
* 不支持 Windows
* Tested with py2.7

## Install
```
pip install scrapy
```

## Download Data
```
cd ChatBotCourse/subtitle/subtitle_crawler
scrapy crawl subtitle
```
Binary file removed subtitle/subtitle_crawler/__init__.pyc
Binary file not shown.
Binary file removed subtitle/subtitle_crawler/items.pyc
Binary file not shown.
13 changes: 8 additions & 5 deletions subtitle/subtitle_crawler/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html
import os
from subprocess import call

DOWNLOAD_CMD = os.path.join(os.path.dirname(
os.path.realpath(__file__)), 'save.sh')

class SubtitleCrawlerPipeline(object):
'''
Download Subtitle with curl
'''
def process_item(self, item, spider):
url = item['url']
file_name = url.replace('/','_').replace(':','_')
fp = open('result/'+file_name, 'w')
fp.write(item['body'])
fp.close()
call([DOWNLOAD_CMD, url])
return item

Binary file removed subtitle/subtitle_crawler/pipelines.pyc
Binary file not shown.
19 changes: 19 additions & 0 deletions subtitle/subtitle_crawler/save.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#! /bin/bash
###########################################
# Save file with CURL
###########################################

# constants
baseDir=$(cd `dirname "$0"`;pwd)
SAVE_PATH=$baseDir/result
# functions

# main
[ -z "${BASH_SOURCE[0]}" -o "${BASH_SOURCE[0]}" = "$0" ] || return
if [ ! -d "$SAVE_PATH" ]; then
# Control will enter here if $DIRECTORY doesn't exist.
mkdir -p $SAVE_PATH
fi

cd $SAVE_PATH
curl -JLO $1
Binary file removed subtitle/subtitle_crawler/settings.pyc
Binary file not shown.
Binary file removed subtitle/subtitle_crawler/spiders/__init__.pyc
Binary file not shown.
Binary file not shown.