PingoBags
Chirping
How's the door working for you? I plan on making a mock door to test in my living room. I'm probably gonna use a pi zero w though, and use the pi 3 for inside projects. I've started making some random functions that I plan on using with my coop pi. You already know I'm not familiar with Python, so I'm probably doing this a dumb way haha, as long as it works.
Here's two messy functions I made this morning to gather some info for me
The input is very minimal, I only need my local wunderground station ID.
I get my coordinates from the xml and use that with geonames to get sunrise/set and time
It outputs
Here's two messy functions I made this morning to gather some info for me
Code:
from urllib2 import urlopen
import xml.etree.ElementTree as ET
def LocalTemp(StationID):
Nodes = ["temperature_string","temp_c","temp_f","relative_humidity","wind_string"]
results = [""] * len(Nodes)
location = [""]*2
sunrise = ""
sunset = ""
time = ""
_l = urlopen("http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=" + StationID)
_xml = _l.read()
_l.close()
content = ET.fromstring(_xml)
for x in range(len(content.tag)):
if content[x].tag == "location":
location[0] = content[x][5].text
location[1] = content[x][6].text
for y in range(len(Nodes)):
if content[x].tag == Nodes[y]:
results[y] = content[x].text
sunrise,sunset,time = RetSun(location[0],location[1])
return (results,location,sunrise,sunset,time)
def RetSun(lat,lng):
_l = urlopen("http://api.geonames.org/timezone?lat=" + lat +"&lng=" + lng +"&username=jed")
_xml = _l.read()
_l.close()
content = ET.fromstring(_xml)
sunrise = ""
sunset = ""
time = ""
for x in range(len(content[0][0].tag)):
if content[0][x].tag == "sunrise":
sunrise = content[0][x].text
if content[0][x].tag == "sunset":
sunset = content[0][x].text
if content[0][x].tag == "time":
time = content[0][x].text
return (sunrise,sunset,time)
results,location,sunrise,sunset,datetime = LocalTemp("IGRANDLA87")
for x in results:
print(x)
for x in location:
print(x)
print(sunrise)
print(sunset)
print(datetime)
The input is very minimal, I only need my local wunderground station ID.
I get my coordinates from the xml and use that with geonames to get sunrise/set and time
It outputs
Code:
59.4 F (15.2 C) #Temp
15.2 #Temp C
59.4 #Temp F
98 #Humidity
From the NNW at 3.0 MPH #Wind direction and speed
44.881039 #Lat
-63.575298 #Long
2017-11-19 07:16 #Sunrise
2017-11-19 16:42 #Sunset
2017-11-19 16:02 #Current Time
>>>