Skip to content
This repository was archived by the owner on Jun 29, 2023. It is now read-only.

Commit baaa88c

Browse files
committed
now python3 compatible. and using requests. cos' its beautiful.
1 parent 82f283a commit baaa88c

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
departures = obersendling.get_departures()
77

88
for departure in departures:
9-
print(departure['product'] + departure['label'] + "\t" + departure['destination'] + "\t" + unicode(departure['departureTimeMinutes']))
9+
print(departure['product'] + departure['label'] + "\t" + departure['destination'] + "\t" + str(departure['departureTimeMinutes']))
1010

1111
print(get_nearby_stations(48.0933264, 11.537161699999999))
1212

mvg/__init__.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# coding=utf-8
22

3-
import urllib2
3+
import requests
44
import json
55
import datetime
66
from time import mktime
@@ -14,10 +14,8 @@
1414

1515

1616
def _perform_api_request(url):
17-
opener = urllib2.build_opener()
18-
opener.addheaders = [('X-MVG-Authorization-Key', api_key)]
19-
response = opener.open(url)
20-
return json.loads(response.read())
17+
resp = requests.get(url, headers={'X-MVG-Authorization-Key': api_key})
18+
return resp.json()
2119

2220

2321
def _convert_time(time):
@@ -61,7 +59,7 @@ def get_locations(query):
6159
if isinstance(query, int):
6260
url = query_url + str(query)
6361
else:
64-
url = query_url + urllib2.quote(query)
62+
url = query_url + query
6563
results = _perform_api_request(url)
6664
return results["locations"]
6765

@@ -148,7 +146,7 @@ class Station:
148146
"""
149147

150148
def __init__(self, station):
151-
if isinstance(station, str) or isinstance(station, unicode):
149+
if isinstance(station, str):
152150
self.station_id = get_id_for_station(station)
153151
if self.station_id is None:
154152
raise NameError("No matching station found")

0 commit comments

Comments
 (0)