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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyTransportNSWv2
3
- Version: 0.5.3
3
+ Version: 0.5.5
4
4
  Summary: Get detailed per-trip transport information from TransportNSW
5
5
  Home-page: https://github.com/andystewart999/TransportNSW
6
6
  Author: andystewart999
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyTransportNSWv2
3
- Version: 0.5.3
3
+ Version: 0.5.5
4
4
  Summary: Get detailed per-trip transport information from TransportNSW
5
5
  Home-page: https://github.com/andystewart999/TransportNSW
6
6
  Author: andystewart999
@@ -140,36 +140,17 @@ class TransportNSWv2(object):
140
140
  found_journeys = 0
141
141
  no_valid_journeys = False
142
142
 
143
- for current_journey in range (0, retrieved_journeys, 1):
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'][current_journey]
147
- next_journey = current_journey + 1
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, next_journey = self.find_next_journey(result['journeys'], current_journey, transport_type, strict_transport_type)
151
-
152
- if (journey is None) or (journey['legs']) is None:
153
- #We've reached the end
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 = 'UNKNOWN'
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
- + self.get_url(origin_mode)
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
- self.info = {
272
- ATTR_DUE_IN: due,
273
- ATTR_ORIGIN_STOP_ID : origin_stop_id,
274
- ATTR_ORIGIN_NAME : origin_name,
275
- ATTR_DEPARTURE_TIME : origin_departure_time,
276
- ATTR_DESTINATION_STOP_ID : destination_stop_id,
277
- ATTR_DESTINATION_NAME : destination_name,
278
- ATTR_ARRIVAL_TIME : destination_arrival_time,
279
- ATTR_ORIGIN_TRANSPORT_TYPE : origin_mode,
280
- ATTR_ORIGIN_TRANSPORT_NAME: origin_mode_name,
281
- ATTR_ORIGIN_LINE_NAME : origin_line_name,
282
- ATTR_ORIGIN_LINE_NAME_SHORT : origin_line_name_short,
283
- ATTR_CHANGES: changes,
284
- ATTR_OCCUPANCY : occupancy,
285
- ATTR_REAL_TIME_TRIP_ID : realtimetripid,
286
- ATTR_LATITUDE : latitude,
287
- ATTR_LONGITUDE : longitude
288
- }
289
-
290
- found_journeys = found_journeys + 1
291
-
292
- # Add to the return array
293
- if (no_valid_journeys == True):
294
- break
295
-
296
- if (found_journeys >= 2):
297
- json_output = json_output + ',' + json.dumps(self.info)
298
- else:
299
- json_output = json_output + json.dumps(self.info)
300
-
301
- if (found_journeys == journeys_to_return):
302
- break
303
-
304
- current_journey = next_journey
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, start_journey, journeytype, strict):
323
- # Find the next journey that has a leg of the requested type
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 start_journey > journey_count:
305
+ if start_journey_index > journey_count:
328
306
  return None, None
329
307
 
330
- for journey in range (start_journey, journey_count, 1):
331
- leg = self.find_first_leg(journeys[journey]['legs'], journeytype, strict)
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[journey], journey + 1
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 leg in range (0, leg_count, 1):
345
- leg_class = legs[leg]['transportation']['product']['class']
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[leg]
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[leg]
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 leg in range (leg_count - 1, -1, -1):
367
- leg_class = legs[leg]['transportation']['product']['class']
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[leg]
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[leg]
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 leg in range (0, leg_count, 1):
391
- leg_class = legs[leg]['transportation']['product']['class']
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.3",
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,