#import dependencies
import requests
import datetime
from xml.dom import minidom
b = 0
i = 0
while (b!= -1):
realtime= str(datetime.datetime.now()).split()[1][0:5]
realtime_split = realtime.split(':')
realtime_hour = int(realtime_split[0])
realtime_min = int(realtime_split[1])
time = realtime_hour*60+realtime_min
g = requests.get("http://truetime.portauthority.org/bustime/api/v1/getpredictions?key=VFkqS4yiFyqxAfdgvsrnQ783F&stpid=7097")
with open("Output.txt", "w") as text_file:
print(g.text, file=text_file)
xmldoc = minidom.parse("Output.txt")
itemlist = xmldoc.getElementsByTagName('prdtm')
timeDif =[]
for s in itemlist:
bustime_split = s.firstChild.nodeValue.split()[1].split(':')
bustime = int(bustime_split[0])*60 +int(bustime_split[1])
timeDif.append(int(bustime-time))
r = requests.post("https://api.particle.io/v1/devices/22002b001351353432393433/brew", data={'access_token': 'ada24d2045a440d9f975c0861224febe6b414065', 'args': timeDif[0]})
r = requests.post("https://api.particle.io/v1/devices/22002b001351353432393433/brew2", data={'access_token': 'ada24d2045a440d9f975c0861224febe6b414065', 'args': timeDif[1]})
print(r.status_code, r.reason)
print(r.text)
a=r.text.split(',')
b=a[3].split(':')[1]
b=b[:-1]
b= int(b)
i=i+1
print(i)
print('request stopped')
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .