20 lines
796 B
Python
Executable file
20 lines
796 B
Python
Executable file
#!/usr/bin/python3
|
|
|
|
import xml.etree.ElementTree as ET
|
|
from datetime import datetime as dt
|
|
from urllib import request
|
|
|
|
xml = request.urlopen('https://www.yr.no/place/Czech_Republic/Olomouc/Ruda_nad_Moravou/forecast.xml').read()
|
|
|
|
root = ET.fromstring(xml)
|
|
days = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su']
|
|
|
|
for time in root.iter('time'):
|
|
attrib = time.attrib
|
|
time_from = dt.strptime(attrib['from'], '%Y-%m-%dT%H:%M:%S')
|
|
time_to = dt.strptime(attrib['to'], '%Y-%m-%dT%H:%M:%S')
|
|
style = time.find('symbol').attrib
|
|
temperature = time.find('temperature').attrib
|
|
preci = time.find('precipitation')
|
|
output = days[time_from.weekday()] + time_from.strftime(' %H') + '-' + time_to.strftime("%Hh") + ': ' + temperature['value'] + '°C' + ', ' + style['name']
|
|
print(output.replace('Partly', 'Pt.'))
|