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

Python3 port of stylometry #8

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
applying futurize
laprice committed Nov 6, 2018
commit cf630c3bf5f4b5f45c7295909d87d1cf6743f0a9
16 changes: 10 additions & 6 deletions stylometry/download.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from __future__ import print_function
from future import standard_library
standard_library.install_aliases()
import os
import csv
from urllib2 import urlopen, URLError, HTTPError
from urllib.request import urlopen
from urllib.error import URLError, HTTPError

def gutenberg_mirror_download(row):
try:
@@ -11,16 +15,16 @@ def gutenberg_mirror_download(row):
url = "http://mirrors.xmission.com/gutenberg/" + path
# url = "http://www.gutenberg.org/ebooks/%d.txt.utf-8" % int(row['gutenberg_id'])
f = urlopen(url)
print "downloading " + url
print("downloading " + url)
if not os.path.exists(row['author']):
os.makedirs(row['author'])
with open(row['author'] + '/' + row['title'] + '.txt', "wb") as local_file:
local_file.write(f.read())

except HTTPError, e:
print "HTTP Error:", e.code, url
except URLError, e:
print "URL Error:", e.reason, url
except HTTPError as e:
print("HTTP Error:", e.code, url)
except URLError as e:
print("URL Error:", e.reason, url)

def gutenberg():
with open(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'gutenberg_mirror.csv'),'rb') as csvfile: