Python 3.x 如何添加开放式天气图';s天气图1.0使用python?
如何使用python添加open weather map的weather map 1.0?Python 3.x 如何添加开放式天气图';s天气图1.0使用python?,python-3.x,Python 3.x,如何使用python添加open weather map的weather map 1.0? 是否要打开该站点?请更精确一点。你想要实现什么?你有自己的代码吗?我想用python预览天气图1.0?谢谢。但我不需要天气。我需要1.0版的天气图。 import configparser import requests import sys def get_api_key(): config = configparser.ConfigParser() config.read('conf
是否要打开该站点?请更精确一点。你想要实现什么?你有自己的代码吗?我想用python预览天气图1.0?谢谢。但我不需要天气。我需要1.0版的天气图。
import configparser
import requests
import sys
def get_api_key():
config = configparser.ConfigParser()
config.read('config.ini')
return config['openweathermap']['api']
def get_weather(api_key, location):
url = "https://api.openweathermap.org/data/2.5/weather?q={}&units=metric&appid=
{}".format(location, api_key)
r = requests.get(url)
return r.json()
def main():
if len(sys.argv) != 2:
exit("Usage: {} LOCATION".format(sys.argv[0]))
location = sys.argv[1]
api_key = get_api_key()
weather = get_weather(api_key, location)
print(weather['main']['temp'])
print(weather)
if __name__ == '__main__':
main()