It is a memorandum when the weather in Osaka was acquired via WebAPI (python).
Please refer to the following. For weather information, please refer to the website of www.drk7.jp.
Distribute the weather forecast information of the Japan Meteorological Agency in XML Getting Precipitation Probability from XML in Python
weather.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import datetime
import requests
import xml.etree.ElementTree as ET
def chance_of_rain(pref_url, date):
if date is None:
date = datetime.datetime.today().strftime("%Y/%m/%d")
root = ET.fromstring(requests.get(pref_url).content)
for area in root.iter('area'):
for info in area.findall('info'):
if info.get('date') == date:
rainfallchance = info.find('rainfallchance')
for period in rainfallchance.findall('period'):
yield period.get('hour'), period.text
if __name__ == '__main__':
prefecture = 'http://www.drk7.jp/weather/xml/27.xml'
hours = '00-06', '06-12', '12-18', '18-24'
date = datetime.datetime.today().strftime("%Y/%m/%d")
print('Precipitation probability in Osaka', date)
for hour, percent in chance_of_rain(prefecture, date):
if hour in hours:
print('%sh %s%%' % (hour, percent))
$ python weather.py
Precipitation probability in Osaka 2019/08/13
00-06h 0%
06-12h 0%
12-18h 10%
18-24h 10%
How can I visualize it in a nice way?
Distribute the weather forecast information of the Japan Meteorological Agency in XML Getting Precipitation Probability from XML in Python A story that took a lot of time to get the probability of precipitation [Python] raspberry pi Added weather forecast to table clock Try using Tkinter in Python
Recommended Posts