Openweathermapで東京と大阪の気象情報を取得してその気象情報をsqlite3に格納するプログラムを書きたいいと思っています。そこで辞書型のデータをsqlite3に格納するにはどのようにすればよろしいのか教えていただきたいです。
該当のソースコード
python
1import sqlite3 2from contextlib import closing 3import requests 4import json 5 6API_KEY = "-------" 7api = "http://api.openweathermap.org/data/2.5/weather?units=metric&q={city}&APPID={key}" 8tokyo_url = api.format(city = 'Tokyo', key = API_KEY) 9 10API_KEY = "-------" 11api = "http://api.openweathermap.org/data/2.5/weather?units=metric&q={city}&APPID={key}" 12osaka_url = api.format(city = 'Osaka', key = API_KEY) 13response = requests.get(osaka_url) 14osaka_data = response.json() 15print(osaka_data)
{'coord': {'lon': 135.5, 'lat': 34.7}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'base': 'stations', 'main': {'temp': 19.5, 'pressure': 1015, 'humidity': 52, 'temp_min': 19, 'temp_max': 20}, 'visibility': 10000, 'wind': {'speed': 1}, 'clouds': {'all': 75}, 'dt': 1539824400, 'sys': {'type': 1, 'id': 7583, 'message': 0.0557, 'country': 'JP', 'sunrise': 1539810343, 'sunset': 1539850811}, 'id': 1853909, 'name': 'Osaka', 'cod': 200}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/19 03:49