forked from swharden/pyHamLog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lookup.py
50 lines (44 loc) · 1.62 KB
/
lookup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import sqlite3
class lookupDb:
def lookupCall(self,call):
query='SELECT * from calldb WHERE call="%s";'%call
data=self.c.execute(query).fetchone()
if data==None: return None
call,name,addr,city,state,zipc=data
return [call,name,addr,city,state,zipc]
def locCall(self,call,countryOnly=True):
while len(call)>0:
query='SELECT * from locs WHERE call="%s";'%call
data=self.c.execute(query).fetchone()
if not data==None: break
call=call[:-1]
prefix,country,continent,latitude,longitude,star,itu,cq=data
if countryOnly: return country
else: return data
def htmlLookup(self,call):
out="""<html>
<body onload="window.top.enter.qth.value='~';">
<br><b>%s</b><br>@</body></html>"""%(call)
country=self.locCall(call)
if country=="USA":
callInfo=self.lookupCall(call)
if callInfo==None:
out=out.replace("@","no info")
out=out.replace("~","")
return
call,name,addr,city,state,zipc=callInfo
msg="%s<br>%s, %s, USA"%(name,city,state)
out=out.replace("@",msg)
out=out.replace("~",state)
return out
else:
out=out.replace("@",country)
out=out.replace("~",country)
return out
def connect(self):
print "connecting to local lookup database"
self.con=sqlite3.connect('./data/db.sqlite')
self.c=self.con.cursor()
self.table='locs'
def disconnect(self):
self.con.close()