fixed unicode bug with sqlite3

pull/3/head
Jeff Laughlin 2014-01-06 22:53:45 -05:00
rodzic 7bce78ae08
commit 16ca716609
2 zmienionych plików z 28 dodań i 10 usunięć

Wyświetl plik

@ -43,6 +43,8 @@ CABRILLO_FIELDS = ['header', 'freq', 'mode', 'date', 'time',
CACHEPATH = os.path.join(os.environ['HOME'], '.qrz_cache') CACHEPATH = os.path.join(os.environ['HOME'], '.qrz_cache')
class NullLoc(Exception): pass
class Log(object): class Log(object):
def __init__(self): def __init__(self):
self.qsos = [] self.qsos = []
@ -67,9 +69,16 @@ class Log(object):
def georeference(self, sess, ctydat): def georeference(self, sess, ctydat):
try: try:
rec = sess.qrz(self.callsign) rec = sess.qrz(self.callsign)
assert None not in (rec['lat'], rec['lon']) if None in (rec['lat'], rec['lon']):
raise NullLoc()
self.lat, self.lon = rec['lat'], rec['lon'] self.lat, self.lon = rec['lat'], rec['lon']
log.debug("qrz rec %s" % rec) log.debug("qrz rec %s" % rec)
except NullLoc:
log.warning("QRZ lookup failed for %s, no location data" % self.callsign)
raise
except qrz.NotFound, e:
log.warning("QRZ lookup failed for %s, not found" % self.callsign)
raise
except Exception, e: except Exception, e:
log.warning("QRZ lookup failed for %s" % self.callsign, exc_info=True) log.warning("QRZ lookup failed for %s" % self.callsign, exc_info=True)
raise raise
@ -82,10 +91,16 @@ class Log(object):
if rec['call'] != qso['to_call']: if rec['call'] != qso['to_call']:
log.warning("qrz %s != %s" % (rec['call'], log.warning("qrz %s != %s" % (rec['call'],
qso['to_call'])) qso['to_call']))
assert None not in (rec['lat'], rec['lon']) if None in (rec['lat'], rec['lon']):
raise NullLoc()
qso['lat'], qso['lon'] = rec['lat'], rec['lon'] qso['lat'], qso['lon'] = rec['lat'], rec['lon']
except Exception, e: except Exception, e:
log.warning("QRZ lookup failed for %s" % qso['to_call'], exc_info=True) if isinstance(e, qrz.NotFound):
log.warning("QRZ lookup failed for %s, not found" % qso['to_call'])
elif isinstance(e, NullLoc):
log.warning("QRZ lookup failed for %s, no location data" % qso['to_call'])
else:
log.warning("QRZ lookup failed for %s" % qso['to_call'], exc_info=True)
try: try:
dxcc = ctydat.getdxcc(qso['to_call']) dxcc = ctydat.getdxcc(qso['to_call'])
qso['lat'] = float(dxcc['lat']) qso['lat'] = float(dxcc['lat'])
@ -116,14 +131,14 @@ class Log(object):
) )
def geolog(logfile, outfile, username, password): def geolog(logfile, outfile, username, password, cachepath):
with open(logfile) as logfile: with open(logfile) as logfile:
log.info("Opened %r" % logfile) log.info("Opened %r" % logfile)
qsolog = Log.from_cabrillo(logfile) qsolog = Log.from_cabrillo(logfile)
with open('/home/jeff/Downloads/ctydat/cty.dat') as ctydat: with open('/home/jeff/Downloads/ctydat/cty.dat') as ctydat:
ctydat = CtyDat(ctydat) ctydat = CtyDat(ctydat)
with qrz.Session(username, password) as sess: with qrz.Session(username, password, cachepath) as sess:
qsolog.georeference(sess, ctydat) qsolog.georeference(sess, ctydat)
points, lines = qsolog.geojson_dumps(sort_keys=True) points, lines = qsolog.geojson_dumps(sort_keys=True)
@ -145,9 +160,9 @@ def main(argv=None):
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description= description=
"""Read ham log and output GIS data for callsigns worked. """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
Output files will be prefixed with output path. created: "foo/bar_points.geojson", "foo/bar_lines.geojson", and "foo/bar.kml"
""") """)
parser.add_argument('infile', type=str, parser.add_argument('infile', type=str,
help='Input log file (ADIF or Cabrillo)') help='Input log file (ADIF or Cabrillo)')
@ -169,7 +184,7 @@ Output files will be prefixed with output path.
un = raw_input("QRZ.com user name:") un = raw_input("QRZ.com user name:")
try: try:
un = cfg.get('qrz', 'password') pw = cfg.get('qrz', 'password')
except ConfigParser.Error: except ConfigParser.Error:
pw = raw_input("QRZ.com password (not stored):") pw = raw_input("QRZ.com password (not stored):")
@ -178,7 +193,9 @@ Output files will be prefixed with output path.
except ConfigParser.Error: except ConfigParser.Error:
cachepath = CACHEPATH cachepath = CACHEPATH
geolog(args.infile, args.outfile, un, pw, cachepath) log.info("QRZ cache: %s" % cachepath)
geolog(args.infile, args.outpath, un, pw, cachepath)
return 0 return 0

Wyświetl plik

@ -70,6 +70,7 @@ class Session(object):
self.checkErr(session) self.checkErr(session)
self.key = session.getElementsByTagName("Key")[0].firstChild.data self.key = session.getElementsByTagName("Key")[0].firstChild.data
self.db = sqlite3.connect(cachepath) self.db = sqlite3.connect(cachepath)
self.db.text_factory = str
try: try:
self.db.execute(""" self.db.execute("""
create table dict ( create table dict (