Fixed import of urlopen[2] on Python 3.

This commit is contained in:
Jochen Kupperschmidt
2016-06-06 00:07:27 +02:00
parent e7e67834c8
commit 811a7c2a44

View File

@ -13,7 +13,13 @@ from datetime import datetime, timedelta
import itertools import itertools
import json import json
import math import math
import urllib2 try:
# Python 3+
from urllib.error import HTTPError, URLError
from urllib.request import urlopen
except ImportError:
# Python 2
from urllib2 import HTTPError, URLError, urlopen
GITHUB_BASE_URL = 'https://github.com/' GITHUB_BASE_URL = 'https://github.com/'
@ -199,8 +205,8 @@ def get_calendar(username, base_url):
try: try:
url = base_url + '/contributions' url = base_url + '/contributions'
page = urllib2.urlopen(url) page = urlopen(url)
except (urllib2.HTTPError, urllib2.URLError) as e: except (HTTPError, URLError) as e:
print('There was a problem fetching data from {0}'.format(url)) print('There was a problem fetching data from {0}'.format(url))
print(e) print(e)
raise SystemExit raise SystemExit