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.
Replace the
pyquery
module with thelxml
module.pyquery
wasn't recognizing thelastTime
element in thevehicleLocations
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 withlxml
, and I haven't figured it out yet. Still working on it.1 - Mysterious "random missing stops": some
stop
s (and more rarelyservice
s) are not being inserted to the database. This throws an error later, when python fails while trying to createservice_stop_order
s 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 runrun.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'sNULL
service (created manually in a later line of python code) isn't missing.