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]:
In [3]:
opcon = open('linkz', 'r')
In [4]:
data = opcon.read()
In [5]:
import xmltodict
In [6]:
datadict = xmltodict.parse(data)
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!')
In [ ]: