PyTransportNSWv2 0.7.1__tar.gz → 0.8.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {PyTransportNSWv2-0.7.1 → PyTransportNSWv2-0.8.2}/PKG-INFO +1 -1
- {PyTransportNSWv2-0.7.1 → PyTransportNSWv2-0.8.2}/PyTransportNSWv2.egg-info/PKG-INFO +1 -1
- {PyTransportNSWv2-0.7.1 → PyTransportNSWv2-0.8.2}/TransportNSWv2/TransportNSWv2.py +49 -11
- {PyTransportNSWv2-0.7.1 → PyTransportNSWv2-0.8.2}/setup.py +1 -1
- {PyTransportNSWv2-0.7.1 → PyTransportNSWv2-0.8.2}/LICENSE +0 -0
- {PyTransportNSWv2-0.7.1 → PyTransportNSWv2-0.8.2}/PyTransportNSWv2.egg-info/SOURCES.txt +0 -0
- {PyTransportNSWv2-0.7.1 → PyTransportNSWv2-0.8.2}/PyTransportNSWv2.egg-info/dependency_links.txt +0 -0
- {PyTransportNSWv2-0.7.1 → PyTransportNSWv2-0.8.2}/PyTransportNSWv2.egg-info/requires.txt +0 -0
- {PyTransportNSWv2-0.7.1 → PyTransportNSWv2-0.8.2}/PyTransportNSWv2.egg-info/top_level.txt +0 -0
- {PyTransportNSWv2-0.7.1 → PyTransportNSWv2-0.8.2}/README.md +0 -0
- {PyTransportNSWv2-0.7.1 → PyTransportNSWv2-0.8.2}/TransportNSWv2/__init__.py +0 -0
- {PyTransportNSWv2-0.7.1 → PyTransportNSWv2-0.8.2}/setup.cfg +0 -0
@@ -15,6 +15,7 @@ ATTR_DUE_IN = 'due'
|
|
15
15
|
ATTR_ORIGIN_STOP_ID = 'origin_stop_id'
|
16
16
|
ATTR_ORIGIN_NAME = 'origin_name'
|
17
17
|
ATTR_DEPARTURE_TIME = 'departure_time'
|
18
|
+
ATTR_DELAY = 'delay'
|
18
19
|
|
19
20
|
ATTR_DESTINATION_STOP_ID = 'destination_stop_id'
|
20
21
|
ATTR_DESTINATION_NAME = 'destination_name'
|
@@ -58,6 +59,7 @@ class TransportNSWv2(object):
|
|
58
59
|
ATTR_ORIGIN_STOP_ID : 'n/a',
|
59
60
|
ATTR_ORIGIN_NAME : 'n/a',
|
60
61
|
ATTR_DEPARTURE_TIME : 'n/a',
|
62
|
+
ATTR_DELAY : 'n/a',
|
61
63
|
ATTR_DESTINATION_STOP_ID : 'n/a',
|
62
64
|
ATTR_DESTINATION_NAME : 'n/a',
|
63
65
|
ATTR_ARRIVAL_TIME : 'n/a',
|
@@ -97,6 +99,37 @@ class TransportNSWv2(object):
|
|
97
99
|
itdDate = now_plus_wait.strftime('%Y%m%d')
|
98
100
|
itdTime = now_plus_wait.strftime('%H%M')
|
99
101
|
|
102
|
+
# First, check if the source and dest stops are valid
|
103
|
+
stop_list = [name_origin, name_destination]
|
104
|
+
auth = 'apikey ' + self.api_key
|
105
|
+
header = {'Accept': 'application/json', 'Authorization': auth}
|
106
|
+
|
107
|
+
for stop in stop_list:
|
108
|
+
url = \
|
109
|
+
'https://api.transport.nsw.gov.au/v1/tp/stop_finder?' \
|
110
|
+
'outputFormat=rapidJSON&coordOutputFormat=EPSG%3A4326' \
|
111
|
+
'&type_sf=stop&name_sf=' + stop + \
|
112
|
+
'&TfNSWSF=true'
|
113
|
+
|
114
|
+
# Send the query and return an error if something goes wrong
|
115
|
+
try:
|
116
|
+
response = requests.get(url, headers=header, timeout=20)
|
117
|
+
except:
|
118
|
+
logger.error("Network or Timeout error when calling /v1/tp/stop_finder API")
|
119
|
+
return None
|
120
|
+
|
121
|
+
# If we get bad status code, log error and return with n/a or an empty string
|
122
|
+
if response.status_code != 200:
|
123
|
+
logger.error("Error calling /v1/tp/stop_finder API; check api key")
|
124
|
+
return None
|
125
|
+
|
126
|
+
# Parse the result as a JSON object
|
127
|
+
result = response.json()
|
128
|
+
|
129
|
+
# Just a quick check - the presence of systemMessages signifies an error
|
130
|
+
if 'systemMessages' in result:
|
131
|
+
logger.error("Stop ID " + stop + " does not exist")
|
132
|
+
|
100
133
|
# We don't control how many journeys are returned any more, so need to be careful of running out of valid journeys if there is a filter in place, particularly a strict filter
|
101
134
|
# It would be more efficient to return one journey, check if the filter is met and then retrieve the next one via a new query if not, but for now we'll only be making use of the journeys we've been given
|
102
135
|
|
@@ -111,20 +144,17 @@ class TransportNSWv2(object):
|
|
111
144
|
# '&calcNumberOfTrips=' + str(journeys_to_retrieve) + \
|
112
145
|
|
113
146
|
|
114
|
-
auth = 'apikey ' + self.api_key
|
115
|
-
header = {'Accept': 'application/json', 'Authorization': auth}
|
116
|
-
|
117
147
|
# Send the query and return an error if something goes wrong
|
118
148
|
# Otherwise store the response
|
119
149
|
try:
|
120
150
|
response = requests.get(url, headers=header, timeout=20)
|
121
151
|
except:
|
122
|
-
logger.
|
152
|
+
logger.error("Network or Timeout error")
|
123
153
|
return None
|
124
154
|
|
125
155
|
# If we get bad status code, log error and return with n/a or an empty string
|
126
156
|
if response.status_code != 200:
|
127
|
-
logger.
|
157
|
+
logger.error("Error with the request sent; check api key")
|
128
158
|
return None
|
129
159
|
|
130
160
|
# Parse the result as a JSON object
|
@@ -171,6 +201,13 @@ class TransportNSWv2(object):
|
|
171
201
|
origin_stop_id = origin['id']
|
172
202
|
origin_name = origin['name']
|
173
203
|
origin_departure_time = origin['departureTimeEstimated']
|
204
|
+
origin_departure_time_planned = origin['departureTimePlanned']
|
205
|
+
|
206
|
+
t1 = datetime.strptime(origin_departure_time, fmt).timestamp()
|
207
|
+
t2 = datetime.strptime(origin_departure_time_planned, fmt).timestamp()
|
208
|
+
delay = int((t1-t2) / 60)
|
209
|
+
|
210
|
+
#print (origin_departure_time - origin_departure_time_planned)
|
174
211
|
|
175
212
|
# How long until it leaves?
|
176
213
|
due = self.get_due(datetime.strptime(origin_departure_time, fmt))
|
@@ -254,6 +291,7 @@ class TransportNSWv2(object):
|
|
254
291
|
|
255
292
|
self.info = {
|
256
293
|
ATTR_DUE_IN: due,
|
294
|
+
ATTR_DELAY: delay,
|
257
295
|
ATTR_ORIGIN_STOP_ID : origin_stop_id,
|
258
296
|
ATTR_ORIGIN_NAME : origin_name,
|
259
297
|
ATTR_DEPARTURE_TIME : origin_departure_time,
|
@@ -416,13 +454,13 @@ class TransportNSWv2(object):
|
|
416
454
|
current_leg = legs[leg_index]
|
417
455
|
leg_class = current_leg['transportation']['product']['class']
|
418
456
|
if 'hints' in current_leg:
|
419
|
-
print ("")
|
420
|
-
print ("Found hint(s) for leg " + str(leg_index) )
|
457
|
+
#print ("")
|
458
|
+
#print ("Found hint(s) for leg " + str(leg_index) )
|
421
459
|
hints = current_leg['hints']
|
422
|
-
for hint in hints:
|
423
|
-
print ("Hint:")
|
424
|
-
print (hint)
|
425
|
-
print (" ")
|
460
|
+
#for hint in hints:
|
461
|
+
#print ("Hint:")
|
462
|
+
#print (hint)
|
463
|
+
#print (" ")
|
426
464
|
|
427
465
|
|
428
466
|
|
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
|
|
5
5
|
|
6
6
|
setuptools.setup(
|
7
7
|
name="PyTransportNSWv2",
|
8
|
-
version="0.
|
8
|
+
version="0.8.2",
|
9
9
|
author="andystewart999",
|
10
10
|
description="Get detailed per-trip transport information from TransportNSW",
|
11
11
|
long_description=long_description,
|
File without changes
|
File without changes
|
{PyTransportNSWv2-0.7.1 → PyTransportNSWv2-0.8.2}/PyTransportNSWv2.egg-info/dependency_links.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|