mirror of
https://github.com/dh1tw/pyhamtools.git
synced 2026-04-21 06:13:57 +00:00
corrected negative longitude problem and added clublog user lookup
This commit is contained in:
parent
2c37f422e1
commit
dd6784ae09
15 changed files with 203 additions and 61 deletions
|
|
@ -177,7 +177,7 @@ class LookupLib(object):
|
|||
u'cqz': 32,
|
||||
u'ituz': 56,
|
||||
u'latitude': -12.48,
|
||||
u'longitude': -177.08
|
||||
u'longitude': 177.08
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -255,7 +255,7 @@ class LookupLib(object):
|
|||
{
|
||||
'deleted': False,
|
||||
'country': u'TURKMENISTAN',
|
||||
'longitude': -58.4,
|
||||
'longitude': 58.4,
|
||||
'cqz': 17,
|
||||
'prefix': u'EZ',
|
||||
'latitude': 38.0,
|
||||
|
|
@ -338,7 +338,7 @@ class LookupLib(object):
|
|||
>>> print my_lookuplib.lookup_callsign("VK9XO", timestamp)
|
||||
{
|
||||
'country': u'CHRISTMAS ISLAND',
|
||||
'longitude': -105.7,
|
||||
'longitude': 105.7,
|
||||
'cqz': 29,
|
||||
'adif': 35,
|
||||
'latitude': -10.5,
|
||||
|
|
@ -500,7 +500,7 @@ class LookupLib(object):
|
|||
{
|
||||
'adif': 230,
|
||||
'country': u'Fed. Rep. of Germany',
|
||||
'longitude': -10.0,
|
||||
'longitude': 10.0,
|
||||
'cqz': 14,
|
||||
'ituz': 28,
|
||||
'latitude': 51.0,
|
||||
|
|
@ -691,7 +691,7 @@ class LookupLib(object):
|
|||
for item in jsonLookup:
|
||||
if item == "Name": lookup[const.COUNTRY] = jsonLookup["Name"]
|
||||
elif item == "DXCC": lookup[const.ADIF] = int(jsonLookup["DXCC"])
|
||||
elif item == "Lon": lookup[const.LONGITUDE] = float(jsonLookup["Lon"])
|
||||
elif item == "Lon": lookup[const.LONGITUDE] = float(jsonLookup["Lon"])*(-1)
|
||||
elif item == "Lat": lookup[const.LATITUDE] = float(jsonLookup["Lat"])
|
||||
elif item == "CQZ": lookup[const.CQZ] = int(jsonLookup["CQZ"])
|
||||
elif item == "Continent": lookup[const.CONTINENT] = jsonLookup["Continent"]
|
||||
|
|
@ -1172,7 +1172,7 @@ class LookupLib(object):
|
|||
elif item.tag == "cont":
|
||||
entity[const.CONTINENT] = unicode(item.text)
|
||||
elif item.tag == "long":
|
||||
entity[const.LONGITUDE] = float(item.text)*(-1)
|
||||
entity[const.LONGITUDE] = float(item.text)
|
||||
elif item.tag == "lat":
|
||||
entity[const.LATITUDE] = float(item.text)
|
||||
elif item.tag == "start":
|
||||
|
|
@ -1220,7 +1220,7 @@ class LookupLib(object):
|
|||
elif item.tag == "cont":
|
||||
call_exception[const.CONTINENT] = unicode(item.text)
|
||||
elif item.tag == "long":
|
||||
call_exception[const.LONGITUDE] = float(item.text)*(-1)
|
||||
call_exception[const.LONGITUDE] = float(item.text)
|
||||
elif item.tag == "lat":
|
||||
call_exception[const.LATITUDE] = float(item.text)
|
||||
elif item.tag == "start":
|
||||
|
|
@ -1261,7 +1261,7 @@ class LookupLib(object):
|
|||
elif item.tag == "cont":
|
||||
prefix[const.CONTINENT] = unicode(item.text)
|
||||
elif item.tag == "long":
|
||||
prefix[const.LONGITUDE] = float(item.text)*(-1)
|
||||
prefix[const.LONGITUDE] = float(item.text)
|
||||
elif item.tag == "lat":
|
||||
prefix[const.LATITUDE] = float(item.text)
|
||||
elif item.tag == "start":
|
||||
|
|
@ -1383,7 +1383,7 @@ class LookupLib(object):
|
|||
entry[const.ITUZ] = int(cty_list[item]["ITUZone"])
|
||||
entry[const.CONTINENT] = unicode(cty_list[item]["Continent"])
|
||||
entry[const.LATITUDE] = float(cty_list[item]["Latitude"])
|
||||
entry[const.LONGITUDE] = float(cty_list[item]["Longitude"])
|
||||
entry[const.LONGITUDE] = float(cty_list[item]["Longitude"])*(-1)
|
||||
|
||||
if cty_list[item]["ExactCallsign"]:
|
||||
if call in exceptions_index.keys():
|
||||
|
|
@ -1433,7 +1433,7 @@ class LookupLib(object):
|
|||
else:
|
||||
err_str = "HTTP Status Code: " + str(response.status_code) + " HTTP Response: " + str(response.text)
|
||||
self._logger.error(err_str)
|
||||
if response.text.strip() == error1 or response.text.strip() == error2:
|
||||
if error1 in response.text.strip() or error2 in response.text.strip():
|
||||
raise APIKeyMissingError
|
||||
else:
|
||||
raise LookupError(err_str)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ import re
|
|||
|
||||
import requests
|
||||
import redis
|
||||
import zipfile
|
||||
import json
|
||||
from io import BytesIO
|
||||
from requests.exceptions import ConnectionError, HTTPError, Timeout
|
||||
|
||||
def get_lotw_users(**kwargs):
|
||||
|
|
@ -16,6 +19,7 @@ def get_lotw_users(**kwargs):
|
|||
|
||||
Raises:
|
||||
IOError: When network is unavailable, file can't be downloaded or processed
|
||||
|
||||
ValueError: Raised when data from file can't be read
|
||||
|
||||
Example:
|
||||
|
|
@ -63,8 +67,96 @@ def get_lotw_users(**kwargs):
|
|||
|
||||
return lotw
|
||||
|
||||
def get_clublog_users(**kwargs):
|
||||
"""Download the latest offical list of `Clublog`__ users.
|
||||
|
||||
Args:
|
||||
url (str, optional): Download URL
|
||||
|
||||
Returns:
|
||||
dict: Dictionary containing (if data available) the fields:
|
||||
firstqso, lastqso, last-lotw, lastupload (datetime),
|
||||
locator (string) and oqrs (boolean)
|
||||
|
||||
Raises:
|
||||
IOError: When network is unavailable, file can't be downloaded or processed
|
||||
|
||||
Example:
|
||||
The following example downloads the Clublog user list and returns a dictionary with the data of HC2/AL1O:
|
||||
|
||||
>>> from pyhamtools.qsl import get_clublog_users
|
||||
>>> clublog = get_lotw_users()
|
||||
>>> clublog['HC2/AL1O']
|
||||
{'firstqso': datetime.datetime(2012, 1, 1, 19, 59, 27),
|
||||
'last-lotw': datetime.datetime(2013, 5, 9, 1, 56, 23),
|
||||
'lastqso': datetime.datetime(2013, 5, 5, 6, 39, 3),
|
||||
'lastupload': datetime.datetime(2013, 5, 8, 15, 0, 6),
|
||||
'oqrs': True}
|
||||
|
||||
.. _CLUBLOG: https://secure.clublog.org
|
||||
__ CLUBLOG_
|
||||
|
||||
"""
|
||||
|
||||
url = ""
|
||||
|
||||
clublog = {}
|
||||
|
||||
try:
|
||||
url = kwargs['url']
|
||||
except KeyError:
|
||||
url = "https://secure.clublog.org/clublog-users.json.zip"
|
||||
|
||||
try:
|
||||
result = requests.get(url)
|
||||
except (ConnectionError, HTTPError, Timeout) as e:
|
||||
raise IOError(e)
|
||||
|
||||
|
||||
if result.status_code != requests.codes.ok:
|
||||
raise IOError("HTTP Error: " + str(result.status_code))
|
||||
|
||||
zip_file = zipfile.ZipFile(BytesIO(result.content))
|
||||
files = zip_file.namelist()
|
||||
cl_json_unzipped = zip_file.read(files[0])
|
||||
|
||||
cl_data = json.loads(cl_json_unzipped)
|
||||
|
||||
error_count = 0
|
||||
|
||||
for call, call_data in cl_data.iteritems():
|
||||
try:
|
||||
data = {}
|
||||
if "firstqso" in call_data:
|
||||
if call_data["firstqso"] != None:
|
||||
data["firstqso"] = datetime.strptime(call_data["firstqso"], '%Y-%m-%d %H:%M:%S')
|
||||
if "lastqso" in call_data:
|
||||
if call_data["lastqso"] != None:
|
||||
data["lastqso"] = datetime.strptime(call_data["lastqso"], '%Y-%m-%d %H:%M:%S')
|
||||
if "last-lotw" in call_data:
|
||||
if call_data["last-lotw"] != None:
|
||||
data["last-lotw"] = datetime.strptime(call_data["last-lotw"], '%Y-%m-%d %H:%M:%S')
|
||||
if "lastupload" in call_data:
|
||||
if call_data["lastupload"] != None:
|
||||
data["lastupload"] = datetime.strptime(call_data["lastupload"], '%Y-%m-%d %H:%M:%S')
|
||||
if "locator" in call_data:
|
||||
if call_data["locator"] != None:
|
||||
data["locator"] = call_data["locator"]
|
||||
if "oqrs" in call_data:
|
||||
if call_data["oqrs"] != None:
|
||||
data["oqrs"] = call_data["oqrs"]
|
||||
clublog[call] = data
|
||||
except TypeError: #some date fields contain null instead of a valid datetime string - we ignore them
|
||||
print("Ignoring invalid type in data:", call, call_data)
|
||||
pass
|
||||
except ValueError: #some date fiels are invalid. we ignore them for the moment
|
||||
print("Ignoring invalid data:", call, call_data)
|
||||
pass
|
||||
|
||||
return clublog
|
||||
|
||||
def get_eqsl_users(**kwargs):
|
||||
"""Download the latest official list of EQSL.cc users. The list of users can be found here_.
|
||||
"""Download the latest official list of `EQSL.cc`__ users. The list of users can be found here_.
|
||||
|
||||
Args:
|
||||
url (str, optional): Download URL
|
||||
|
|
@ -85,7 +177,7 @@ def get_eqsl_users(**kwargs):
|
|||
>>> except ValueError as e:
|
||||
>>> print e
|
||||
'DH1TW' is not in list
|
||||
|
||||
|
||||
.. _here: http://www.eqsl.cc/QSLCard/DownloadedFiles/AGMemberlist.txt
|
||||
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
#VERSION = (0, 5, 0, 'dev')
|
||||
VERSION = (0, 5, 6)
|
||||
VERSION = (0, 6, 0)
|
||||
__release__ = ''.join(['-.'[type(x) == int]+str(x) for x in VERSION])[1:]
|
||||
__version__ = '.'.join((str(VERSION[0]), str(VERSION[1])))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue