-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatacollector.py
More file actions
executable file
·34 lines (30 loc) · 952 Bytes
/
datacollector.py
File metadata and controls
executable file
·34 lines (30 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import time
import mysql.connector
from xml.dom import minidom
import urllib2
import os
def executeSomething():
newpid = os.fork()
if newpid == 0:
timestamp = int(time.time());
mydb = mysql.connector.connect(
host="localhost",
user="ubuntu",
passwd="epl606",
database="parking"
)
url = 'http://www.nicosia.org.cy/el-GR/rss/parkingspaces/' # define XML location
dom = minidom.parse(urllib2.urlopen(url)) # parse the data
spaces = dom.getElementsByTagName('spaces')
ids = dom.getElementsByTagName('id')
for x in range(4):
if ids[x].firstChild.nodeValue != "3" :
mycursor = mydb.cursor()
sql = "INSERT INTO data (parking_id, space, timestamp) VALUES (%s, %s, %s)"
val = (str(ids[x].firstChild.nodeValue), str(spaces[x].firstChild.nodeValue), str(timestamp))
mycursor.execute(sql, val)
mydb.commit()
os._exit(0);
time.sleep(300)
while True:
executeSomething()