pmaris / py_nextbus Goto Github PK
View Code? Open in Web Editor NEWMinimalistic Python client for the NextBus public API for real-time transit arrival data
License: MIT License
Minimalistic Python client for the NextBus public API for real-time transit arrival data
License: MIT License
Is it now named py_nextbus or py-nextbus?
Confusing for some package managers...
When trying to import the py_nextbus module, I get the following error. I haven't been able to figure out what it means.
Traceback (most recent call last): File "/home/nick/Documents/Workspaces/BusScheduler/HomeBusSchedule.py", line 1, in <module> import py_nextbus File "/home/nick/Documents/Workspaces/BusScheduler/py_nextbus/__init__.py", line 3, in <module> from .client import NextBusClient File "/home/nick/Documents/Workspaces/BusScheduler/py_nextbus/client.py", line 3, in <module> from urllib.error import HTTPError ImportError: No module named error
When Client().get_vehicle_locations()
is called, it returns a TypeError
.
before_times[i]
is the last time the request was made.
Traceback (most recent call last):
File "program.py", line 51, in <module>
data = client.get_vehicle_locations(route, before_times[i], agency)
File "/home/user/env/lib/python3.5/site-packages/py_nextbus/client.py", line 301, in get_vehicle_locations
return self._perform_request(params=params)
File "/home/user/env/lib/python3.5/site-packages/py_nextbus/client.py", line 367, in _perform_request
response = json.loads(response_text)
File "/usr/lib/python3.5/json/__init__.py", line 312, in loads
s.__class__.__name__))
TypeError: the JSON object must be str, not 'bytes'
Hey @pmaris. Seems like you're no longer maintaining this project. I'm happy to take it over if you want to move it to an org and add me to the Pypi account.
The issue is in this line of code:
py_nextbus/py_nextbus/client.py
Line 234 in 0eeae87
Strings are valid for 'stop_tag'. For example, LA Metro Rail uses 80409_0
and 80409_1
, with the number after the underscore indicating which direction the trains are moving in: https://www.nextbus.com/#!/lametro-rail/804/804_0_var0/80409_0
Casting to an int means that these stops aren't found properly, since the casting process drops the underscore.
I'm seeing the following in my logs when using the client:
Making request to URL http://webservices.nextbus.com/service/publicJSONFeed?command=predictions&a=sf-muni&s=6659&routeTag=36
hass_1 | 2019-01-15 06:22:28 DEBUG (SyncWorker_0) [custom_components.nextbus]
{'copyright': 'All data copyright San Francisco Muni 2019.', 'Error': {'content': 'route parameter "r" must be specified in query string', 'shouldRetry': 'false'}}
I can reproduce and resolve with curl
by switching the param name to r
:
$ curl "http://webservices.nextbus.com/service/publicJSONFeed?command=predictions&a=sf-muni&s=6934&routeTag=36"
{"copyright":"All data copyright San Francisco Muni 2019.","Error":{"content":"route parameter \"r\" must be specified in query string","shouldRetry":"false"}}
$ curl "http://webservices.nextbus.com/service/publicJSONFeed?command=predictions&a=sf-muni&s=6934&r=36"
{"predictions":{"agencyTitle":"San Francisco Muni","routeTag":"36","routeTitle":"36-Teresita","direction":{"title":"Inbound to Forest Hill Station","prediction":{"isDeparture":"false","minutes":"26","seconds":"1608","tripTag":"8239605","vehicle":"8522","affectedByLayover":"true","block":"3603","dirTag":"36___I_N00","epochTime":"1547536388615"}},"stopTitle":"Woodside Ave & Hernandez Ave","stopTag":"6934"},"copyright":"All data copyright San Francisco Muni 2019."}
Seems like a quick fix on line 194.
I can submit a patch tomorrow.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.