Auckland Motor Camera

A project by wcmckee.

This script I run as a cronjob every minute in order to keep the json file updated. It logs into the infoconnect highway cameras. This is a xml file. I am not a big fan of working with xml files. I can do it, but I'd rather json. This gives me access to my

TODO Add more useful data to the json feed.


In [1]:
import subprocess

In [2]:
subprocess.call('curl -k -H "username: williammckee" -H "password: J3e6t8q5y2" -o linkz https://infoconnect1.highwayinfo.govt.nz/ic/jbi/TrafficCameras/REST/FeedService/', shell=True)


Out[2]:
0

In [3]:
opcon = open('linkz', 'r')

In [4]:
data = opcon.read()

In [5]:
import xmltodict


---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-5-e15753873c39> in <module>()
----> 1 import xmltodict

ImportError: No module named xmltodict

In [6]:
datadict = xmltodict.parse(data)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-6-18c68d00eb2d> in <module>()
----> 1 datadict = xmltodict.parse(data)

NameError: name 'xmltodict' is not defined

In [8]:
#savxml = open('/home/will/Desktop/brobeur-static/feeds/aklmcam.json', 'w')
#savxml.write(data)
#savxml.close()

In [9]:
import json
jsononjz = json.dumps(datadict)
#read the data back in
#newDictionary = json.load(datadict)

In [10]:
savcdat = open('/home/wcmckee/brobeur-static/feeds/aklmcam.json', 'w')
savcdat.write(str(jsononjz))
savcdat.close()
print('done uploading feed!')


done uploading feed!

In [ ]: