update fccreferencer to use callook.info

master
Jeff Laughlin 2016-09-27 11:44:04 -04:00
rodzic 3773a15fc6
commit 2b098e0137
3 zmienionych plików z 54 dodań i 35 usunięć

Wyświetl plik

@ -22,18 +22,18 @@ import logging
import os
import sys
import traceback
from pkg_resources import resource_stream
import geojson as gj
from hamtools import adif
from hamtools.ctydat import CtyDat, InvalidDxcc, InvalidCallsign
from hamtools import kml
from hamtools import qrz
import requests
import requests_cache
import adif
from ctydat import CtyDat, InvalidDxcc, InvalidCallsign
import kml
import qrz
log = logging.getLogger('geolog')
#log.setLevel(logging.INFO)
# log.setLevel(logging.INFO)
# 1. Load log
# 2. Georeference log
@ -49,10 +49,16 @@ CACHEPATH = os.path.join(os.environ['HOME'], '.qrz_cache')
class OperatorGeoRefFail(Exception): pass
class GeoRefFail(Exception): pass
class GeoRefError(Exception): pass
class NullLoc(GeoRefError): pass
class NotFound(GeoRefError): pass
@ -91,17 +97,27 @@ class CtyDatReferencer(object):
return lon, lat
# from hamtools.ushams import ushams
# from hamtools.ziplocs import ziplocs
#
# class FCCReferencer(object):
# def reference(self, callsign):
# try:
# zip = ushams[callsign][:5]
# lat, lon = ziplocs[zip]
# except KeyError:
# raise NotFound(callsign)
# return lon, lat
class FCCReferencer(object):
PREFIXES = list('aknw')
CACHEPATH = os.path.join(os.environ.get('XDG_CACHE_HOME', os.environ['HOME']), '.callook_cache')
requests_cache.install_cache(CACHEPATH)
def reference(self, callsign):
if callsign[0].lower() not in self.PREFIXES:
raise NotFound(callsign)
r = requests.get("https://callook.info/%s/json" % callsign)
if r.status_code == 404:
raise NotFound(callsign)
if r.status_code != 200:
raise GeoRefError(r.status_code)
try:
data = r.json()
except ValueError:
raise GeoRefError('bad json')
if data['status'] != 'VALID':
raise GeoRefError('invalid')
lon = float(data['location']['longitude'])
lat = float(data['location']['latitude'])
return lon, lat
class Log(object):
@ -134,10 +150,14 @@ class Log(object):
self = Log()
log = adif.Reader(logfile)
for qso in log:
try: del qso['app_datetime_on']
except KeyError: pass
try: del qso['app_datetime_off']
except KeyError: pass
try:
del qso['app_datetime_on']
except KeyError:
pass
try:
del qso['app_datetime_off']
except KeyError:
pass
self.qsos.append(qso)
self.callsign = qso['operator']
return self
@ -147,14 +167,14 @@ class Log(object):
try:
return d.reference(callsign)
except GeoRefError, e:
log.warning("%r failed on call %s", d, callsign)
log.warning("%r failed on call %s: %s", d, callsign, e)
else:
raise GeoRefFail(callsign)
def georeference(self, sess, ctydat):
drivers = self.drivers = []
sess and drivers.append(QrzReferencer(sess))
# drivers.append(FCCReferencer())
drivers.append(FCCReferencer())
ctydat and drivers.append(CtyDatReferencer(ctydat))
if not drivers:
@ -221,6 +241,7 @@ class Log(object):
folder.appendChild(callnode)
dom.writepretty(file)
def geolog(logfilepath, outfile, username, password, cachepath, ctydatflo):
with open(logfilepath) as logfile:
line = logfile.next()
@ -260,7 +281,7 @@ def main(argv=None):
parser = argparse.ArgumentParser(
description=
"""Read ham log and output GIS data for callsigns worked. Output files will be
"""Read ham log and output GIS data for callsigns worked. Output files will be
prefixed with output path. E.g. given "foo/bar", the following files will be
created: "foo/bar_points.geojson", "foo/bar_lines.geojson", and "foo/bar.kml"
""")
@ -313,4 +334,3 @@ created: "foo/bar_points.geojson", "foo/bar_lines.geojson", and "foo/bar.kml"
if __name__ == "__main__":
sys.exit(main())

Wyświetl plik

@ -97,7 +97,6 @@ class Session(object):
hc = httplib.HTTPConnection("xml.qrz.com")
headers = {"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain"}
hc.request("POST", "/xml", urllib.urlencode(params), headers)
resp = hc.getresponse()
if resp.status != httplib.OK:

Wyświetl plik

@ -12,7 +12,7 @@ setup(
packages = ['hamtools'],
package_data={'hamtools': ['ctydat/cty.dat']},
scripts = ['geolog', 'vk'],
install_requires = ['geojson'],
install_requires = ['geojson', 'requests', 'requests-cache'],
long_description = (
"""Collection of amateur radio tools. Includes ability to read ADIF and
Cabrillo log files, cty.dat files, georeference callsigns via QRZ.com and