-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeteo
More file actions
executable file
·31 lines (23 loc) · 1016 Bytes
/
Copy pathmeteo
File metadata and controls
executable file
·31 lines (23 loc) · 1016 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
#!/usr/bin/python3
import urllib.request, xml.dom.minidom, os.path
def processInfo(v):
print(v["city"], " em ", v["current_date_time"], " ", sep="")
def processCurrent(v):
print("Hoje: ", v["condition"], ", ", v["temp_c"], "°C", sep="")
print(" ", v["humidity"])
print(" ", v["wind_condition"])
print(" ", os.path.basename(v["icon"]), "\n", sep="")
def processForecast(v):
print(v["day_of_week"], ": ", v["condition"], ", ", v["low"], "°C a ", v["high"], "°C\n", sep="")
def getValues(node):
values = {}
for child in node.childNodes:
values[child.nodeName] = child.attributes.item(0).value
return values
f = urllib.request.urlopen('http://www.google.com/ig/api?weather=loures&hl=pt-pt')
dom = xml.dom.minidom.parseString(f.read().decode('ISO-8859-1'))
getTag = dom.getElementsByTagName
processCurrent(getValues(getTag("current_conditions")[0]))
for node in getTag("forecast_conditions"):
processForecast(getValues(node))
processInfo(getValues(getTag("forecast_information")[0]))