Weather module use mapquest module to found city location
This commit is contained in:
parent
46c8048b53
commit
0a96627d6a
1 changed files with 13 additions and 3 deletions
|
|
@ -6,6 +6,8 @@ import re
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
|
|
||||||
|
import mapquest
|
||||||
|
|
||||||
nemubotversion = 3.4
|
nemubotversion = 3.4
|
||||||
|
|
||||||
def load(context):
|
def load(context):
|
||||||
|
|
@ -106,7 +108,15 @@ def treat_coord(msg):
|
||||||
coords = list()
|
coords = list()
|
||||||
coords.append(DATAS.index[j]["lat"])
|
coords.append(DATAS.index[j]["lat"])
|
||||||
coords.append(DATAS.index[j]["long"])
|
coords.append(DATAS.index[j]["long"])
|
||||||
return coords, specific
|
return j, coords, specific
|
||||||
|
|
||||||
|
else:
|
||||||
|
geocode = [x for x in mapquest.geocode(j)]
|
||||||
|
if len(geocode):
|
||||||
|
coords = list()
|
||||||
|
coords.append(geocode[0]["latLng"]["lat"])
|
||||||
|
coords.append(geocode[0]["latLng"]["lng"])
|
||||||
|
return mapquest.where(geocode[0]), coords, specific
|
||||||
|
|
||||||
raise IRCException("Je ne sais pas où se trouve %s." % " ".join(msg.cmds[1:]))
|
raise IRCException("Je ne sais pas où se trouve %s." % " ".join(msg.cmds[1:]))
|
||||||
|
|
||||||
|
|
@ -137,7 +147,7 @@ def cmd_coordinates(msg):
|
||||||
return Response(msg.sender, "Les coordonnées de %s sont %s,%s" % (msg.cmds[1], coords["lat"], coords["long"]), channel=msg.channel)
|
return Response(msg.sender, "Les coordonnées de %s sont %s,%s" % (msg.cmds[1], coords["lat"], coords["long"]), channel=msg.channel)
|
||||||
|
|
||||||
def cmd_alert(msg):
|
def cmd_alert(msg):
|
||||||
coords, specific = treat_coord(msg)
|
loc, coords, specific = treat_coord(msg)
|
||||||
wth = get_json_weather(coords)
|
wth = get_json_weather(coords)
|
||||||
|
|
||||||
res = Response(msg.sender, channel=msg.channel, nomore="No more weather alert", count=" (%d more alerts)")
|
res = Response(msg.sender, channel=msg.channel, nomore="No more weather alert", count=" (%d more alerts)")
|
||||||
|
|
@ -149,7 +159,7 @@ def cmd_alert(msg):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def cmd_weather(msg):
|
def cmd_weather(msg):
|
||||||
coords, specific = treat_coord(msg)
|
loc, coords, specific = treat_coord(msg)
|
||||||
wth = get_json_weather(coords)
|
wth = get_json_weather(coords)
|
||||||
|
|
||||||
res = Response(msg.sender, channel=msg.channel, nomore="No more weather information")
|
res = Response(msg.sender, channel=msg.channel, nomore="No more weather information")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue