near: show users near you. experimental.
This commit is contained in:
parent
d7399e73fa
commit
c065aaa59a
|
@ -198,10 +198,8 @@ def distance(lat1, lon1, lat2, lon2):
|
|||
|
||||
@hook.command(autohelp=False)
|
||||
def near(inp, nick='', chan='', db=None):
|
||||
init_db(db)
|
||||
|
||||
try:
|
||||
loc = db.execute("select lat, lon from location where chan=? and lower(nick)=lower(?)", (chan, nick)).fetchone()
|
||||
loc = db.execute("select lat, lon from location where chan=? and nick=lower(?)", (chan, nick)).fetchone()
|
||||
except db.OperationError:
|
||||
loc = None
|
||||
|
||||
|
@ -212,9 +210,15 @@ def near(inp, nick='', chan='', db=None):
|
|||
|
||||
db.create_function('distance', 4, distance)
|
||||
nearby = db.execute("select nick, distance(lat, lon, ?, ?) as dist from location where chan=?"
|
||||
" limit 20", (lat, lon, chan)).fetchall()
|
||||
" and nick != lower(?) order by dist limit 20", (lat, lon, chan, nick)).fetchall()
|
||||
|
||||
return nearby
|
||||
out = '(km) '
|
||||
last_dist = 10
|
||||
while nearby and len(out) < 200:
|
||||
nick, dist = nearby.pop(0)
|
||||
out += '%s:%.0f ' % (munge(nick, 1), dist)
|
||||
|
||||
return out
|
||||
|
||||
|
||||
character_replacements = {
|
||||
|
|
|
@ -17,7 +17,7 @@ def weather(inp, chan='', nick='', reply=None, db=None, api_key=None):
|
|||
|
||||
# this database is used by other plugins interested in user's locations,
|
||||
# like .near in tag.py
|
||||
db.execute("create table if not exists location(chan, nick, loc, lat, lon, primary key(chan, lower(nick)))")
|
||||
db.execute("create table if not exists location(chan, nick, loc, lat, lon, primary key(chan, nick))")
|
||||
|
||||
loc = inp
|
||||
|
||||
|
@ -27,7 +27,7 @@ def weather(inp, chan='', nick='', reply=None, db=None, api_key=None):
|
|||
|
||||
|
||||
if not loc: # blank line
|
||||
loc = db.execute("select loc from location where chan=? and lower(nick)=lower(?)",
|
||||
loc = db.execute("select loc from location where chan=? and nick=lower(?)",
|
||||
(chan, nick)).fetchone()
|
||||
if not loc:
|
||||
try:
|
||||
|
@ -66,8 +66,7 @@ def weather(inp, chan='', nick='', reply=None, db=None, api_key=None):
|
|||
try:
|
||||
parsed_json = http.get_json(url)
|
||||
except IOError:
|
||||
print 'Could not get data from Wunderground'
|
||||
return None
|
||||
return 'Could not get data from Wunderground'
|
||||
|
||||
info = {}
|
||||
if 'current_observation' not in parsed_json:
|
||||
|
@ -115,7 +114,7 @@ def weather(inp, chan='', nick='', reply=None, db=None, api_key=None):
|
|||
|
||||
if inp and not dontsave:
|
||||
db.execute("insert or replace into location(chan, nick, loc, lat, lon) "
|
||||
"values (?, ?, ?, ?,?)", (chan, nick, inp, lat, lon))
|
||||
"values (?, ?, ?, ?,?)", (chan, nick.lower(), inp, lat, lon))
|
||||
db.commit()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue