XtremeCurling / nextbus2pg

Save nextbus real-time vehicle location data in a postgres database
MIT License
0 stars 0 forks source link

Replace pyquery.PyQuery with lxml.etree #1

Closed XtremeCurling closed 6 years ago

XtremeCurling commented 6 years ago

Replace the pyquery module with the lxml module. pyquery wasn't recognizing the lastTime element in the vehicleLocations endpoint XML; lxml didn't have this problem.

I also suspected that the mysterious "random missing stops"1 were a result of an unexplained inconsistency in pyquery, but this turned out to be wrong; this bug is still popping up with lxml, and I haven't figured it out yet. Still working on it.

1 - Mysterious "random missing stops": some stops (and more rarely services) are not being inserted to the database. This throws an error later, when python fails while trying to create service_stop_orders because a dict() call uses a key (a stop (or service) tag) that doesn't exist. The key doesn't exist because that route's stops (or services) weren't inserted to the database. The offending routes are different every time, which is the real head-scratching part. And sometimes the issue doesn't pop up, or if I run run.py multiple times, eventually all stops and services will be added. The issue has something to do with either (1) retrieving the XML from the API or (2) parsing the XML, because I noticed that when a particular route's services are missing, that route's NULL service (created manually in a later line of python code) isn't missing.