Permalink
Browse files

Added a module for checking/storing CityCycle data for a university p…

…roject.
  • Loading branch information...
1 parent 7477b4f commit 0ebb9a6287484f6256aa199f5d709b9cfb22339f @scottjacksonx committed May 16, 2012
Showing with 37 additions and 0 deletions.
  1. +37 −0 citycycle.py
View
@@ -0,0 +1,37 @@
+import json
+import urllib
+from bs4 import BeautifulSoup
+import time
+import threading
+import sqlite3
+
+interval = 3 * 60
+
+def setup(phenny):
+ def checkCycles(phenny):
+ url = "http://api.citybik.es/citycycle.json"
+ stationsString = str(urllib.urlopen(url).read())
+
+ atts = ["id", "name", "lat", "lng", "bikes", "free", "timestamp"]
+ for att in atts:
+ logging.info("replacing: " + att)
+ stationsString = stationsString.replace(att+":", "\"" + att + "\":")
+
+ stations = json.loads(stationsString)
+
+ """
+ Table cycles:
+
+ int timestamp
+ text json
+ """
+
+ conn = sqlite3.connect("citycycle.db")
+ c = conn.cursor()
+ c.execute("insert into cycles VALUES (?,?", (int(time.time()), json.dumps(stations)))
+ conn.commit()
+ c.close()
+ time.sleep(interval)
+ targs = (phenny,)
+ t = threading.Thread(target=checkCycles, args=targs)
+ t.start()

0 comments on commit 0ebb9a6

Please sign in to comment.