Skip to content

Commit d8c58cd

Browse files
committed
add 2 & 3 compatibility
1 parent 109889d commit d8c58cd

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

download.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1+
from __future__ import print_function
12
import os
23
import re
3-
import urllib2
4+
from six.moves.urllib.request import urlopen
5+
from six.moves.urllib.error import HTTPError
46
import shutil
57
import argparse
68
import mistune
79
import bs4 as BeautifulSoup
10+
import socket
811

912
def download_pdf(link, location, name):
1013
try:
11-
response = urllib2.urlopen(link, timeout=500)
14+
response = urlopen(link, timeout=500)
1215
file = open(os.path.join(location, name), 'w')
1316
file.write(response.read())
1417
file.close()
15-
except urllib2.HTTPError:
18+
except HTTPError:
1619
print('>>> Error 404: cannot be downloaded!\n')
1720
raise
1821
except socket.timeout:

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
mistune>=0.7.2
2-
beautifulsoup4>=4.4.1
2+
beautifulsoup4>=4.4.1
3+
six>=1.10.0

0 commit comments

Comments
 (0)