import requests, json
def main():
# 参数
cityname = input("请输入你想查询的城市天气:")
key = '2e2883171ff8e8b957793be62b2ec56c'
get_weather( cityname, key)
def get_weather( cityname, key):
url = 'http://api.tianapi.com/txapi/tianqi/index'
params = 'city={}&key={}'.format( cityname, key)
city_weather = requests.get(url, params)
#print(city_weather)
result = json.loads(city_weather.text)
print(result['newslist'][0])
time =result['newslist'][0]['date']
week=result['newslist'][0]['week']
weather=result['newslist'][0]['weather']
lowest=result['newslist'][0]['lowest']
highest=result['newslist'][0]['highest']
tips=result['newslist'][0]['tips']
print(time,week,weather,lowest,highest)
print(tips)
if __name__ == "__main__":
main()