[mapquest] Dusting + fill help

This commit is contained in:
nemunaire 2015-12-01 00:49:09 +01:00
parent a089efff1a
commit c9801ee2f7

View File

@ -1,7 +1,7 @@
# coding=utf-8
"""Transform name location to GPS coordinates""" """Transform name location to GPS coordinates"""
# PYTHON STUFFS #######################################################
import re import re
from urllib.parse import quote from urllib.parse import quote
@ -9,12 +9,15 @@ from nemubot.exception import IMException
from nemubot.hooks import hook from nemubot.hooks import hook
from nemubot.tools import web from nemubot.tools import web
nemubotversion = 4.0
from more import Response from more import Response
# GLOBALS #############################################################
URL_API = "http://open.mapquestapi.com/geocoding/v1/address?key=%s&location=%%s" URL_API = "http://open.mapquestapi.com/geocoding/v1/address?key=%s&location=%%s"
# LOADING #############################################################
def load(context): def load(context):
if not context.config or "apikey" not in context.config: if not context.config or "apikey" not in context.config:
raise ImportError("You need a MapQuest API key in order to use this " raise ImportError("You need a MapQuest API key in order to use this "
@ -25,9 +28,7 @@ def load(context):
URL_API = URL_API % context.config["apikey"].replace("%", "%%") URL_API = URL_API % context.config["apikey"].replace("%", "%%")
def help_full(): # MODULE CORE #########################################################
return "!geocode /place/: get coordinate of /place/."
def geocode(location): def geocode(location):
obj = web.getJSON(URL_API % quote(location)) obj = web.getJSON(URL_API % quote(location))
@ -43,7 +44,13 @@ def where(loc):
"{adminArea1}".format(**loc)).strip() "{adminArea1}".format(**loc)).strip()
@hook.command("geocode") # MODULE INTERFACE ####################################################
@hook.command("geocode",
help="Get GPS coordinates of a place",
help_usage={
"PLACE": "Get GPS coordinates of PLACE"
})
def cmd_geocode(msg): def cmd_geocode(msg):
if not len(msg.args): if not len(msg.args):
raise IMException("indicate a name") raise IMException("indicate a name")