mirror of
https://github.com/craigerl/aprsd.git
synced 2025-03-08 04:18:59 -05:00
cleaned up weather code after switch to requests ... from urllib. works on py2 and py3
This commit is contained in:
parent
00432cf5bb
commit
ad0f96d1aa
@ -867,25 +867,19 @@ def server(loglevel, quiet):
|
|||||||
# get my last location from aprsis then get weather from
|
# get my last location from aprsis then get weather from
|
||||||
# weather service
|
# weather service
|
||||||
try:
|
try:
|
||||||
LOG.debug("A")
|
|
||||||
url = ("http://api.aprs.fi/api/get?" "&what=loc&apikey=104070.f9lE8qg34L8MZF&format=json" "&name=%s" % fromcall)
|
url = ("http://api.aprs.fi/api/get?" "&what=loc&apikey=104070.f9lE8qg34L8MZF&format=json" "&name=%s" % fromcall)
|
||||||
#response = urllib.urlopen(url)
|
#response = urllib.urlopen(url)
|
||||||
LOG.debug("B")
|
|
||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
#aprs_data = json.loads(response.read())
|
#aprs_data = json.loads(response.read())
|
||||||
LOG.debug("C")
|
|
||||||
aprs_data = json.loads(response.text)
|
aprs_data = json.loads(response.text)
|
||||||
lat = aprs_data['entries'][0]['lat']
|
lat = aprs_data['entries'][0]['lat']
|
||||||
lon = aprs_data['entries'][0]['lng']
|
lon = aprs_data['entries'][0]['lng']
|
||||||
url2 = ("https://forecast.weather.gov/MapClick.php?lat=%s" "&lon=%s&FcstType=json" % (lat, lon))
|
url2 = ("https://forecast.weather.gov/MapClick.php?lat=%s" "&lon=%s&FcstType=json" % (lat, lon))
|
||||||
LOG.debug("D")
|
|
||||||
#response2 = urllib.urlopen(url2)
|
#response2 = urllib.urlopen(url2)
|
||||||
response2 = requests.get(url2)
|
response2 = requests.get(url2)
|
||||||
LOG.debug("E")
|
|
||||||
#wx_data = json.loads(response2.read())
|
#wx_data = json.loads(response2.read())
|
||||||
wx_data = json.loads(response2.text)
|
wx_data = json.loads(response2.text)
|
||||||
print(wx_data)
|
print(wx_data)
|
||||||
LOG.debug("F")
|
|
||||||
reply = "%sF(%sF/%sF) %s. %s, %s." % (
|
reply = "%sF(%sF/%sF) %s. %s, %s." % (
|
||||||
wx_data['currentobservation']['Temp'],
|
wx_data['currentobservation']['Temp'],
|
||||||
wx_data['data']['temperature'][0],
|
wx_data['data']['temperature'][0],
|
||||||
@ -893,14 +887,8 @@ def server(loglevel, quiet):
|
|||||||
wx_data['data']['weather'][0],
|
wx_data['data']['weather'][0],
|
||||||
wx_data['time']['startPeriodName'][1],
|
wx_data['time']['startPeriodName'][1],
|
||||||
wx_data['data']['weather'][1])
|
wx_data['data']['weather'][1])
|
||||||
|
LOG.debug("reply: " + reply.rstrip())
|
||||||
# unicode to ascii
|
send_message(fromcall, reply.rstrip())
|
||||||
LOG.debug("F")
|
|
||||||
reply = reply.rstrip()
|
|
||||||
LOG.debug("G")
|
|
||||||
LOG.debug("reply: " + reply)
|
|
||||||
send_message(fromcall, reply)
|
|
||||||
LOG.debug("H")
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.debug("Weather failed with: " + "%s" % str(e))
|
LOG.debug("Weather failed with: " + "%s" % str(e))
|
||||||
reply = "Unable to find you (send beacon?)"
|
reply = "Unable to find you (send beacon?)"
|
||||||
|
Loading…
Reference in New Issue
Block a user