PyTransportNSWv2 0.5.3__tar.gz → 0.5.4__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.4}/PKG-INFO +1 -1
- {PyTransportNSWv2-0.5.3 → PyTransportNSWv2-0.5.4}/PyTransportNSWv2.egg-info/PKG-INFO +1 -1
- {PyTransportNSWv2-0.5.3 → PyTransportNSWv2-0.5.4}/TransportNSWv2/TransportNSWv2.py +76 -83
- {PyTransportNSWv2-0.5.3 → PyTransportNSWv2-0.5.4}/setup.py +1 -1
- {PyTransportNSWv2-0.5.3 → PyTransportNSWv2-0.5.4}/LICENSE +0 -0
- {PyTransportNSWv2-0.5.3 → PyTransportNSWv2-0.5.4}/PyTransportNSWv2.egg-info/SOURCES.txt +0 -0
- {PyTransportNSWv2-0.5.3 → PyTransportNSWv2-0.5.4}/PyTransportNSWv2.egg-info/dependency_links.txt +0 -0
- {PyTransportNSWv2-0.5.3 → PyTransportNSWv2-0.5.4}/PyTransportNSWv2.egg-info/requires.txt +0 -0
- {PyTransportNSWv2-0.5.3 → PyTransportNSWv2-0.5.4}/PyTransportNSWv2.egg-info/top_level.txt +0 -0
- {PyTransportNSWv2-0.5.3 → PyTransportNSWv2-0.5.4}/README.md +0 -0
- {PyTransportNSWv2-0.5.3 → PyTransportNSWv2-0.5.4}/TransportNSWv2/__init__.py +0 -0
- {PyTransportNSWv2-0.5.3 → PyTransportNSWv2-0.5.4}/setup.cfg +0 -0
@@ -134,42 +134,30 @@ class TransportNSWv2(object):
|
|
134
134
|
exit
|
135
135
|
|
136
136
|
retrieved_journeys = len(result['journeys'])
|
137
|
+
print ("retrieved_journeys = " + str(retrieved_journeys))
|
137
138
|
|
138
139
|
# Loop through the results applying filters where required, and generate the appropriate JSON output including an array of in-scope trips
|
139
140
|
json_output=''
|
140
141
|
found_journeys = 0
|
141
142
|
no_valid_journeys = False
|
142
143
|
|
143
|
-
for
|
144
|
+
for current_journey_index in range (0, retrieved_journeys, 1):
|
145
|
+
print(current_journey_index)
|
144
146
|
if transport_type == 0:
|
145
147
|
# Just grab the next trip
|
146
|
-
journey = result['journeys'][
|
147
|
-
|
148
|
+
journey = result['journeys'][current_journey_index]
|
149
|
+
next_journey_index = current_journey_index + 1
|
148
150
|
else:
|
149
151
|
# 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
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
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
|
-
}
|
152
|
+
print ("transport_type = " + str(transport_type))
|
153
|
+
journey, next_journey_index = self.find_next_journey(result['journeys'], current_journey_index, transport_type, strict_transport_type)
|
154
|
+
if (journey is None):
|
155
|
+
print ("Just called find_next_journey")
|
156
|
+
print ("journey is None")
|
157
|
+
|
158
|
+
if ((journey is None) or (journey['legs']) is None):
|
159
|
+
print ("This journey isn't valid, moving to the next one")
|
160
|
+
|
173
161
|
else:
|
174
162
|
legs = journey['legs']
|
175
163
|
first_leg = self.find_first_leg(legs, transport_type, strict_transport_type)
|
@@ -181,7 +169,6 @@ class TransportNSWv2(object):
|
|
181
169
|
destination = last_leg['destination']
|
182
170
|
transportation = first_leg['transportation']
|
183
171
|
|
184
|
-
|
185
172
|
# Origin info
|
186
173
|
origin_stop_id = origin['id']
|
187
174
|
origin_name = origin['name']
|
@@ -216,7 +203,7 @@ class TransportNSWv2(object):
|
|
216
203
|
origin_line_name = transportation['number']
|
217
204
|
|
218
205
|
# Occupancy info, if it's there
|
219
|
-
occupancy = '
|
206
|
+
occupancy = 'unknown'
|
220
207
|
if 'properties' in first_stop:
|
221
208
|
if 'occupancy' in first_stop['properties']:
|
222
209
|
occupancy = first_stop['properties']['occupancy']
|
@@ -230,22 +217,21 @@ class TransportNSWv2(object):
|
|
230
217
|
# Build the URL
|
231
218
|
url = \
|
232
219
|
'https://api.transport.nsw.gov.au/v1/gtfs/vehiclepos' \
|
233
|
-
|
220
|
+
+ self.get_url(origin_mode)
|
234
221
|
auth = 'apikey ' + self.api_key
|
235
222
|
header = {'Authorization': auth}
|
236
223
|
|
237
224
|
response = requests.get(url, headers=header, timeout=10)
|
238
|
-
|
239
225
|
# Only try and process the results if we got a good return code
|
240
226
|
if response.status_code == 200:
|
241
227
|
# Search the feed and see if we can find the trip_id
|
242
228
|
# If we do, capture the latitude and longitude
|
243
|
-
|
244
229
|
feed = gtfs_realtime_pb2.FeedMessage()
|
245
230
|
feed.ParseFromString(response.content)
|
246
231
|
|
247
232
|
# Unfortunately we need to do some mucking about for train-based trip_ids
|
248
233
|
# Define the appropriate regular expression to search for - usually just the full text
|
234
|
+
print ( feed.entity[0] )
|
249
235
|
bFindLocation = True
|
250
236
|
|
251
237
|
if origin_mode == 'Train':
|
@@ -268,40 +254,40 @@ class TransportNSWv2(object):
|
|
268
254
|
# We found it, so break out
|
269
255
|
break
|
270
256
|
|
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
|
-
|
257
|
+
self.info = {
|
258
|
+
ATTR_DUE_IN: due,
|
259
|
+
ATTR_ORIGIN_STOP_ID : origin_stop_id,
|
260
|
+
ATTR_ORIGIN_NAME : origin_name,
|
261
|
+
ATTR_DEPARTURE_TIME : origin_departure_time,
|
262
|
+
ATTR_DESTINATION_STOP_ID : destination_stop_id,
|
263
|
+
ATTR_DESTINATION_NAME : destination_name,
|
264
|
+
ATTR_ARRIVAL_TIME : destination_arrival_time,
|
265
|
+
ATTR_ORIGIN_TRANSPORT_TYPE : origin_mode,
|
266
|
+
ATTR_ORIGIN_TRANSPORT_NAME: origin_mode_name,
|
267
|
+
ATTR_ORIGIN_LINE_NAME : origin_line_name,
|
268
|
+
ATTR_ORIGIN_LINE_NAME_SHORT : origin_line_name_short,
|
269
|
+
ATTR_CHANGES: changes,
|
270
|
+
ATTR_OCCUPANCY : occupancy,
|
271
|
+
ATTR_REAL_TIME_TRIP_ID : realtimetripid,
|
272
|
+
ATTR_LATITUDE : latitude,
|
273
|
+
ATTR_LONGITUDE : longitude
|
274
|
+
}
|
275
|
+
|
276
|
+
found_journeys = found_journeys + 1
|
277
|
+
|
278
|
+
# Add to the return array
|
279
|
+
if (no_valid_journeys == True):
|
280
|
+
break
|
281
|
+
|
282
|
+
if (found_journeys >= 2):
|
283
|
+
json_output = json_output + ',' + json.dumps(self.info)
|
284
|
+
else:
|
285
|
+
json_output = json_output + json.dumps(self.info)
|
286
|
+
|
287
|
+
if (found_journeys == journeys_to_return):
|
288
|
+
break
|
289
|
+
|
290
|
+
current_journey_index = next_journey_index
|
305
291
|
|
306
292
|
json_output='{"journeys_to_return": ' + str(self.journeys_to_return) + ', "journeys_with_data": ' + str(found_journeys) + ', "journeys": [' + json_output + ']}'
|
307
293
|
return json_output
|
@@ -319,60 +305,67 @@ class TransportNSWv2(object):
|
|
319
305
|
# return None
|
320
306
|
|
321
307
|
|
322
|
-
def find_next_journey(self, journeys,
|
323
|
-
#
|
308
|
+
def find_next_journey(self, journeys, start_journey_index, journeytype, strict):
|
309
|
+
# Fnd the next journey that has a leg of the requested type
|
324
310
|
journey_count = len(journeys)
|
311
|
+
print ("(find_next_journey): start_journey_index = " + str(start_journey_index))
|
312
|
+
print ("(find_next_journey): journey_count = " + str(journey_count))
|
325
313
|
|
326
314
|
# Some basic error checking
|
327
|
-
if
|
315
|
+
if start_journey_index > journey_count:
|
316
|
+
print ("None, None")
|
328
317
|
return None, None
|
329
318
|
|
330
|
-
for
|
331
|
-
leg = self.find_first_leg(journeys[
|
319
|
+
for journey_index in range (start_journey_index, journey_count, 1):
|
320
|
+
leg = self.find_first_leg(journeys[journey_index]['legs'], journeytype, strict)
|
332
321
|
if leg is not None:
|
333
|
-
|
322
|
+
print ("leg is not None")
|
323
|
+
return journeys[journey_index], journey_index + 1
|
334
324
|
else:
|
325
|
+
print ("leg is None, None")
|
335
326
|
return None, None
|
336
327
|
|
337
328
|
# Hmm, we didn't find one
|
338
|
-
return None
|
329
|
+
return None, None
|
339
330
|
|
340
331
|
|
341
332
|
def find_first_leg(self, legs, legtype, strict):
|
342
333
|
# Find the first leg of the requested type
|
343
334
|
leg_count = len(legs)
|
344
|
-
|
345
|
-
|
346
|
-
|
335
|
+
print ("leg_count = " + str(leg_count))
|
336
|
+
for leg_index in range (0, leg_count, 1):
|
337
|
+
leg_class = legs[leg_index]['transportation']['product']['class']
|
338
|
+
print("leg_class = " + str(leg_class))
|
347
339
|
# We've got a filter, and the leg type matches it, so return that leg
|
348
340
|
if legtype != 0 and leg_class == legtype:
|
349
|
-
return legs[
|
341
|
+
return legs[leg_index]
|
350
342
|
|
351
343
|
# We don't have a filter, and this is the first non-walk/cycle leg so return that leg
|
352
344
|
if legtype == 0 and leg_class < 99:
|
353
|
-
return legs[
|
345
|
+
return legs[leg_index]
|
354
346
|
|
355
347
|
# Exit if we're doing strict filtering and we haven't found that type in the first leg
|
356
348
|
if legtype != 0 and strict == True:
|
357
349
|
return None
|
358
350
|
|
359
351
|
# Hmm, we didn't find one
|
352
|
+
print ("Fell through to None")
|
360
353
|
return None
|
361
354
|
|
362
355
|
|
363
356
|
def find_last_leg(self, legs, legtype, strict):
|
364
357
|
# Find the last leg of the requested type
|
365
358
|
leg_count = len(legs)
|
366
|
-
for
|
367
|
-
leg_class = legs[
|
359
|
+
for leg_index in range (leg_count - 1, -1, -1):
|
360
|
+
leg_class = legs[leg_index]['transportation']['product']['class']
|
368
361
|
|
369
362
|
# We've got a filter, and the leg type matches it, so return that leg
|
370
363
|
if legtype != 0 and leg_class == legtype:
|
371
|
-
return legs[
|
364
|
+
return legs[leg_index]
|
372
365
|
|
373
366
|
# We don't have a filter, and this is the first non-walk/cycle leg so return that leg
|
374
367
|
if legtype == 0 and leg_class < 99:
|
375
|
-
return legs[
|
368
|
+
return legs[leg_index]
|
376
369
|
|
377
370
|
# Exit if we're doing strict filtering and we haven't found that type in the first leg
|
378
371
|
if legtype != 0 and strict == True:
|
@@ -387,8 +380,8 @@ class TransportNSWv2(object):
|
|
387
380
|
changes = 0
|
388
381
|
leg_count = len(legs)
|
389
382
|
|
390
|
-
for
|
391
|
-
leg_class = legs[
|
383
|
+
for leg_index in range (0, leg_count, 1):
|
384
|
+
leg_class = legs[leg_index]['transportation']['product']['class']
|
392
385
|
if leg_class == legtype or legtype == 0:
|
393
386
|
changes = changes + 1
|
394
387
|
|
@@ -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.4",
|
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.4}/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
|