'''
Retrieve station locations from the xml and update the database table.
To be run daily in a cron job when the other script isn't running.
'''

import xmltodict # have to load
import requests

url = "https://secure.niceridemn.org/data2/bikeStations.xml"
@@ -171,12 +171,15 @@
  to 
-load
+install
 %0Aimp
@@ -196,64 +196,732 @@
 ts%0A%0A
-url = %22https://secure.niceridemn.org/data2/bikeStations.xml%22
+import datetime%0A%0Aimport psycopg2%0Afrom pgconnect import pgconnect%0A%0Aurl = %22https://secure.niceridemn.org/data2/bikeStations.xml%22%0Ar = requests.get(url)%0A%0Astations = xmltodict.parse(r.content)%0A%0Adb = pgconnect%5B'db'%5D%0Auser = pgconnect%5B'user'%5D%0Ahost = pgconnect%5B'host'%5D%0A%0Acon = psycopg2.connect(database=db, user=user, host=host, port=5432)%0Acur = con.cursor()%0A%0A#drop table and recreate %0Acur.execute(open(%22create_id_loc.sql%22).read())%0Acon.commit()%0A%0Asql = %22INSERT INTO niceride_mn.id_loc(id,geom,created_at) VALUES (%25s,ST_SetSRID(ST_MakePoint(%25s,%25s),4326),%25s)%22%0Afor station in stations%5B'stations'%5D%5B'station'%5D:%0A    now = datetime.datetime.now()%0A    cur.execute(sql,(station%5B'id'%5D, station%5B'lat'%5D,station%5B'long'%5D,now))%0Acon.commit()%0A%0Acon.close()%0A

update script done