Created
February 16, 2021 06:21
-
-
Save basictomonokai/fb5e0a98bdfd4180316be66f85e25ca0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import xml.etree.ElementTree as ET | |
import folium | |
url = 'http://api.nmzu.jp/history.xml' | |
response = requests.get(url) | |
response.encoding = response.apparent_encoding | |
# XMLを取得 | |
root = ET.fromstring(response.text) | |
names = [] | |
namef = 0 | |
for name in root.iter('name'): | |
if namef == 0: | |
namef = 1 | |
else: | |
names.append(name.text) | |
detection_dates = [] | |
for detection_date in root.iter('detection_date'): | |
detection_dates.append(detection_date.text) | |
intensity_nos = [] | |
for intensity_no in root.iter('intensity_no'): | |
intensity_nos.append(intensity_no.text) | |
magnitudes = [] | |
for magnitude in root.iter('magnitude'): | |
magnitudes.append(magnitude.text) | |
urls = [] | |
for url in root.iter('url'): | |
urls.append(url.text) | |
latitudes = [] | |
for latitude in root.iter('latitude'): | |
latitudes.append(float(latitude.text)) | |
longitudes = [] | |
for longitude in root.iter('longitude'): | |
longitudes.append(float(longitude.text)) | |
cnt = 0 | |
title_data = "" | |
for name1 in names: | |
#print(name1,detection_dates[cnt],intensity_nos[cnt],magnitudes[cnt],urls[cnt],latitudes[cnt],longitudes[cnt]) | |
title_data += name1+' 日時:'+detection_dates[cnt]+' 震度:'+intensity_nos[cnt]+' M:'+magnitudes[cnt]+' <a target="_blank" href="'+urls[cnt]+'">詳細</a> 緯度経度:'+str(latitudes[cnt])+','+str(longitudes[cnt])+'<br>' | |
cnt += 1 | |
loc = 'Corpus Christi' | |
title_html = title_data.format(loc) | |
stations = names; | |
# 地図生成(新宿駅中心) | |
folium_map = folium.Map(location=[35.690921, 139.700258], zoom_start=6) | |
folium_map.get_root().html.add_child(folium.Element(title_html)) | |
# マーカープロット | |
cnt = 0 | |
for station in stations: | |
folium.Marker( | |
location=[latitudes[cnt], longitudes[cnt]], | |
popup=station+":"+intensity_nos[cnt], | |
icon=folium.Icon(color='red') | |
).add_to(folium_map) | |
cnt += 1 | |
# 地図表示 | |
folium_map |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment