控制台——Python新手——需要知道如何检查URL是否被发送
发布时间:2022-04-22 18:45:27 209
相关标签: # node.js
我需要知道URL是否被发送,因为我似乎没有收到任何回复,没有错误消息,没有数据,什么都没有。就像脚本运行,但什么都不做。这是密码。
#!/usr/bin/env python
import sys
import simplejson, urllib
city = sys.argv[1]
country = sys.argv[2]
temp_celsius = 0
url = "http://api.openweathermap.org/data/2.5/weather"
apikey = "My Key Goes Here"
# to get API Key go here
# http://openweathermap.org/appid
# API Description:
# http://bugs.openweathermap.org/projects/api/wiki/Weather_Data
if not apikey:
sys.exit(1)
try:
result = simplejson.load(urllib.urlopen("%s?appid=%s&q=%s,%s" % (url, apikey, city, country)))
except:
sys.exit(1)
temp_celsius = result['main']['temp'] - 273.15
humidity_percent = result['main']['humidity']
pressure_hpa = result['main']['pressure']
wind_mps = result['wind']['speed']
dict_out = {}
dict_out["temp"] = str(temp_celsius)
dict_out["humidity"] = str(humidity_percent)
dict_out["wind_speed"] = str(wind_mps)
dict_out["pressure"] = str(pressure_hpa)
output = ""
for k in dict_out.keys():
output = "%s %s:%s" % (output, k, dict_out[k])
sys.stdout.write(output)
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报