mirror of
https://github.com/craigerl/aprsd.git
synced 2024-12-19 16:15:57 -05:00
switch from urlib to requests for weather, tested in py3 and py2. still need to update locate, and all other http calls
This commit is contained in:
parent
4b09fad876
commit
00432cf5bb
@ -37,7 +37,9 @@ import sys
|
|||||||
# import telnetlib
|
# import telnetlib
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import urllib
|
#import urllib
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
import click
|
import click
|
||||||
import click_completion
|
import click_completion
|
||||||
@ -865,17 +867,25 @@ 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:
|
||||||
url = ("http://api.aprs.fi/api/get?"
|
LOG.debug("A")
|
||||||
"&what=loc&apikey=104070.f9lE8qg34L8MZF&format=json"
|
url = ("http://api.aprs.fi/api/get?" "&what=loc&apikey=104070.f9lE8qg34L8MZF&format=json" "&name=%s" % fromcall)
|
||||||
"&name=%s" % fromcall)
|
#response = urllib.urlopen(url)
|
||||||
response = urllib.urlopen(url)
|
LOG.debug("B")
|
||||||
aprs_data = json.loads(response.read())
|
response = requests.get(url)
|
||||||
|
#aprs_data = json.loads(response.read())
|
||||||
|
LOG.debug("C")
|
||||||
|
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"
|
url2 = ("https://forecast.weather.gov/MapClick.php?lat=%s" "&lon=%s&FcstType=json" % (lat, lon))
|
||||||
"&lon=%s&FcstType=json" % (lat, lon))
|
LOG.debug("D")
|
||||||
response2 = urllib.urlopen(url2)
|
#response2 = urllib.urlopen(url2)
|
||||||
wx_data = json.loads(response2.read())
|
response2 = requests.get(url2)
|
||||||
|
LOG.debug("E")
|
||||||
|
#wx_data = json.loads(response2.read())
|
||||||
|
wx_data = json.loads(response2.text)
|
||||||
|
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],
|
||||||
@ -885,9 +895,14 @@ def server(loglevel, quiet):
|
|||||||
wx_data['data']['weather'][1])
|
wx_data['data']['weather'][1])
|
||||||
|
|
||||||
# unicode to ascii
|
# unicode to ascii
|
||||||
reply = reply.encode('ascii', errors='ignore')
|
LOG.debug("F")
|
||||||
send_message(fromcall, reply.rstrip())
|
reply = reply.rstrip()
|
||||||
except Exception:
|
LOG.debug("G")
|
||||||
|
LOG.debug("reply: " + reply)
|
||||||
|
send_message(fromcall, reply)
|
||||||
|
LOG.debug("H")
|
||||||
|
except Exception as e:
|
||||||
|
LOG.debug("Weather failed with: " + "%s" % str(e))
|
||||||
reply = "Unable to find you (send beacon?)"
|
reply = "Unable to find you (send beacon?)"
|
||||||
send_message(fromcall, reply)
|
send_message(fromcall, reply)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user