PyTransportNSWv2 0.5.3__tar.gz → 0.5.5__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.5.3 → PyTransportNSWv2-0.5.5}/PKG-INFO +1 -1
- {PyTransportNSWv2-0.5.3 → PyTransportNSWv2-0.5.5}/PyTransportNSWv2.egg-info/PKG-INFO +1 -1
- {PyTransportNSWv2-0.5.3 → PyTransportNSWv2-0.5.5}/TransportNSWv2/TransportNSWv2.py +60 -83
- {PyTransportNSWv2-0.5.3 → PyTransportNSWv2-0.5.5}/setup.py +1 -1
- {PyTransportNSWv2-0.5.3 → PyTransportNSWv2-0.5.5}/LICENSE +0 -0
- {PyTransportNSWv2-0.5.3 → PyTransportNSWv2-0.5.5}/PyTransportNSWv2.egg-info/SOURCES.txt +0 -0
- {PyTransportNSWv2-0.5.3 → PyTransportNSWv2-0.5.5}/PyTransportNSWv2.egg-info/dependency_links.txt +0 -0
- {PyTransportNSWv2-0.5.3 → PyTransportNSWv2-0.5.5}/PyTransportNSWv2.egg-info/requires.txt +0 -0
- {PyTransportNSWv2-0.5.3 → PyTransportNSWv2-0.5.5}/PyTransportNSWv2.egg-info/top_level.txt +0 -0
- {PyTransportNSWv2-0.5.3 → PyTransportNSWv2-0.5.5}/README.md +0 -0
- {PyTransportNSWv2-0.5.3 → PyTransportNSWv2-0.5.5}/TransportNSWv2/__init__.py +0 -0
- {PyTransportNSWv2-0.5.3 → PyTransportNSWv2-0.5.5}/setup.cfg +0 -0
@@ -140,36 +140,17 @@ class TransportNSWv2(object):
|
|
140
140
|
found_journeys = 0
|
141
141
|
no_valid_journeys = False
|
142
142
|
|
143
|
-
for
|
143
|
+
for current_journey_index in range (0, retrieved_journeys, 1):
|
144
144
|
if transport_type == 0:
|
145
145
|
# Just grab the next trip
|
146
|
-
journey = result['journeys'][
|
147
|
-
|
146
|
+
journey = result['journeys'][current_journey_index]
|
147
|
+
next_journey_index = current_journey_index + 1
|
148
148
|
else:
|
149
149
|
# Look for a trip with a matching class filter in at least one of its legs. Either ANY, or the first leg, depending on how strict we're being
|
150
|
-
journey,
|
151
|
-
|
152
|
-
if (journey is None) or (journey['legs']) is None:
|
153
|
-
|
154
|
-
no_valid_journeys = True
|
155
|
-
self.info = {
|
156
|
-
ATTR_DUE_IN : 'n/a',
|
157
|
-
ATTR_ORIGIN_STOP_ID : 'n/a',
|
158
|
-
ATTR_ORIGIN_NAME : 'n/a',
|
159
|
-
ATTR_DEPARTURE_TIME : 'n/a',
|
160
|
-
ATTR_DESTINATION_STOP_ID : 'n/a',
|
161
|
-
ATTR_DESTINATION_NAME : 'n/a',
|
162
|
-
ATTR_ARRIVAL_TIME : 'n/a',
|
163
|
-
ATTR_ORIGIN_TRANSPORT_TYPE : 'n/a',
|
164
|
-
ATTR_ORIGIN_TRANSPORT_NAME : 'n/a',
|
165
|
-
ATTR_ORIGIN_LINE_NAME : 'n/a',
|
166
|
-
ATTR_ORIGIN_LINE_NAME_SHORT : 'n/a',
|
167
|
-
ATTR_CHANGES : 'n/a',
|
168
|
-
ATTR_OCCUPANCY : 'n/a',
|
169
|
-
ATTR_REAL_TIME_TRIP_ID : 'n/a',
|
170
|
-
ATTR_LATITUDE : 'n/a',
|
171
|
-
ATTR_LONGITUDE : 'n/a'
|
172
|
-
}
|
150
|
+
journey, next_journey_index = self.find_next_journey(result['journeys'], current_journey_index, transport_type, strict_transport_type)
|
151
|
+
|
152
|
+
if ((journey is None) or (journey['legs']) is None):
|
153
|
+
pass
|
173
154
|
else:
|
174
155
|
legs = journey['legs']
|
175
156
|
first_leg = self.find_first_leg(legs, transport_type, strict_transport_type)
|
@@ -181,7 +162,6 @@ class TransportNSWv2(object):
|
|
181
162
|
destination = last_leg['destination']
|
182
163
|
transportation = first_leg['transportation']
|
183
164
|
|
184
|
-
|
185
165
|
# Origin info
|
186
166
|
origin_stop_id = origin['id']
|
187
167
|
origin_name = origin['name']
|
@@ -216,7 +196,7 @@ class TransportNSWv2(object):
|
|
216
196
|
origin_line_name = transportation['number']
|
217
197
|
|
218
198
|
# Occupancy info, if it's there
|
219
|
-
occupancy = '
|
199
|
+
occupancy = 'unknown'
|
220
200
|
if 'properties' in first_stop:
|
221
201
|
if 'occupancy' in first_stop['properties']:
|
222
202
|
occupancy = first_stop['properties']['occupancy']
|
@@ -230,17 +210,15 @@ class TransportNSWv2(object):
|
|
230
210
|
# Build the URL
|
231
211
|
url = \
|
232
212
|
'https://api.transport.nsw.gov.au/v1/gtfs/vehiclepos' \
|
233
|
-
|
213
|
+
+ self.get_url(origin_mode)
|
234
214
|
auth = 'apikey ' + self.api_key
|
235
215
|
header = {'Authorization': auth}
|
236
216
|
|
237
217
|
response = requests.get(url, headers=header, timeout=10)
|
238
|
-
|
239
218
|
# Only try and process the results if we got a good return code
|
240
219
|
if response.status_code == 200:
|
241
220
|
# Search the feed and see if we can find the trip_id
|
242
221
|
# If we do, capture the latitude and longitude
|
243
|
-
|
244
222
|
feed = gtfs_realtime_pb2.FeedMessage()
|
245
223
|
feed.ParseFromString(response.content)
|
246
224
|
|
@@ -268,40 +246,40 @@ class TransportNSWv2(object):
|
|
268
246
|
# We found it, so break out
|
269
247
|
break
|
270
248
|
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
249
|
+
self.info = {
|
250
|
+
ATTR_DUE_IN: due,
|
251
|
+
ATTR_ORIGIN_STOP_ID : origin_stop_id,
|
252
|
+
ATTR_ORIGIN_NAME : origin_name,
|
253
|
+
ATTR_DEPARTURE_TIME : origin_departure_time,
|
254
|
+
ATTR_DESTINATION_STOP_ID : destination_stop_id,
|
255
|
+
ATTR_DESTINATION_NAME : destination_name,
|
256
|
+
ATTR_ARRIVAL_TIME : destination_arrival_time,
|
257
|
+
ATTR_ORIGIN_TRANSPORT_TYPE : origin_mode,
|
258
|
+
ATTR_ORIGIN_TRANSPORT_NAME: origin_mode_name,
|
259
|
+
ATTR_ORIGIN_LINE_NAME : origin_line_name,
|
260
|
+
ATTR_ORIGIN_LINE_NAME_SHORT : origin_line_name_short,
|
261
|
+
ATTR_CHANGES: changes,
|
262
|
+
ATTR_OCCUPANCY : occupancy,
|
263
|
+
ATTR_REAL_TIME_TRIP_ID : realtimetripid,
|
264
|
+
ATTR_LATITUDE : latitude,
|
265
|
+
ATTR_LONGITUDE : longitude
|
266
|
+
}
|
267
|
+
|
268
|
+
found_journeys = found_journeys + 1
|
269
|
+
|
270
|
+
# Add to the return array
|
271
|
+
if (no_valid_journeys == True):
|
272
|
+
break
|
273
|
+
|
274
|
+
if (found_journeys >= 2):
|
275
|
+
json_output = json_output + ',' + json.dumps(self.info)
|
276
|
+
else:
|
277
|
+
json_output = json_output + json.dumps(self.info)
|
278
|
+
|
279
|
+
if (found_journeys == journeys_to_return):
|
280
|
+
break
|
281
|
+
|
282
|
+
current_journey_index = next_journey_index
|
305
283
|
|
306
284
|
json_output='{"journeys_to_return": ' + str(self.journeys_to_return) + ', "journeys_with_data": ' + str(found_journeys) + ', "journeys": [' + json_output + ']}'
|
307
285
|
return json_output
|
@@ -319,38 +297,37 @@ class TransportNSWv2(object):
|
|
319
297
|
# return None
|
320
298
|
|
321
299
|
|
322
|
-
def find_next_journey(self, journeys,
|
323
|
-
#
|
300
|
+
def find_next_journey(self, journeys, start_journey_index, journeytype, strict):
|
301
|
+
# Fnd the next journey that has a leg of the requested type
|
324
302
|
journey_count = len(journeys)
|
325
303
|
|
326
304
|
# Some basic error checking
|
327
|
-
if
|
305
|
+
if start_journey_index > journey_count:
|
328
306
|
return None, None
|
329
307
|
|
330
|
-
for
|
331
|
-
leg = self.find_first_leg(journeys[
|
308
|
+
for journey_index in range (start_journey_index, journey_count, 1):
|
309
|
+
leg = self.find_first_leg(journeys[journey_index]['legs'], journeytype, strict)
|
332
310
|
if leg is not None:
|
333
|
-
return journeys[
|
311
|
+
return journeys[journey_index], journey_index + 1
|
334
312
|
else:
|
335
313
|
return None, None
|
336
314
|
|
337
315
|
# Hmm, we didn't find one
|
338
|
-
return None
|
316
|
+
return None, None
|
339
317
|
|
340
318
|
|
341
319
|
def find_first_leg(self, legs, legtype, strict):
|
342
320
|
# Find the first leg of the requested type
|
343
321
|
leg_count = len(legs)
|
344
|
-
for
|
345
|
-
leg_class = legs[
|
346
|
-
|
322
|
+
for leg_index in range (0, leg_count, 1):
|
323
|
+
leg_class = legs[leg_index]['transportation']['product']['class']
|
347
324
|
# We've got a filter, and the leg type matches it, so return that leg
|
348
325
|
if legtype != 0 and leg_class == legtype:
|
349
|
-
return legs[
|
326
|
+
return legs[leg_index]
|
350
327
|
|
351
328
|
# We don't have a filter, and this is the first non-walk/cycle leg so return that leg
|
352
329
|
if legtype == 0 and leg_class < 99:
|
353
|
-
return legs[
|
330
|
+
return legs[leg_index]
|
354
331
|
|
355
332
|
# Exit if we're doing strict filtering and we haven't found that type in the first leg
|
356
333
|
if legtype != 0 and strict == True:
|
@@ -363,16 +340,16 @@ class TransportNSWv2(object):
|
|
363
340
|
def find_last_leg(self, legs, legtype, strict):
|
364
341
|
# Find the last leg of the requested type
|
365
342
|
leg_count = len(legs)
|
366
|
-
for
|
367
|
-
leg_class = legs[
|
343
|
+
for leg_index in range (leg_count - 1, -1, -1):
|
344
|
+
leg_class = legs[leg_index]['transportation']['product']['class']
|
368
345
|
|
369
346
|
# We've got a filter, and the leg type matches it, so return that leg
|
370
347
|
if legtype != 0 and leg_class == legtype:
|
371
|
-
return legs[
|
348
|
+
return legs[leg_index]
|
372
349
|
|
373
350
|
# We don't have a filter, and this is the first non-walk/cycle leg so return that leg
|
374
351
|
if legtype == 0 and leg_class < 99:
|
375
|
-
return legs[
|
352
|
+
return legs[leg_index]
|
376
353
|
|
377
354
|
# Exit if we're doing strict filtering and we haven't found that type in the first leg
|
378
355
|
if legtype != 0 and strict == True:
|
@@ -387,8 +364,8 @@ class TransportNSWv2(object):
|
|
387
364
|
changes = 0
|
388
365
|
leg_count = len(legs)
|
389
366
|
|
390
|
-
for
|
391
|
-
leg_class = legs[
|
367
|
+
for leg_index in range (0, leg_count, 1):
|
368
|
+
leg_class = legs[leg_index]['transportation']['product']['class']
|
392
369
|
if leg_class == legtype or legtype == 0:
|
393
370
|
changes = changes + 1
|
394
371
|
|
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
|
|
5
5
|
|
6
6
|
setuptools.setup(
|
7
7
|
name="PyTransportNSWv2",
|
8
|
-
version="0.5.
|
8
|
+
version="0.5.5",
|
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.5.3 → PyTransportNSWv2-0.5.5}/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
|