updated some api stuff
This commit is contained in:
parent
f75aeea2a9
commit
a997e37718
|
@ -32,6 +32,7 @@ if not os.path.exists('config'):
|
|||
"tvdb": "INSERT API KEY FROM thetvdb.com HERE",
|
||||
"bitly_user": "INSERT USERNAME FROM bitly.com HERE",
|
||||
"bitly_api": "INSERT API KEY FROM bitly.com HERE",
|
||||
"woflramalpha": "INSERT API KEY FROM wolframalpha.com HERE",
|
||||
"mc_user": "INSERT MINECRAFT USERNAME HERE (used to check login servers in mclogin.py)",
|
||||
"mc_pass": "INSERT MINECRAFT PASSWORD HERE (used to check login servers in mclogin.py)"
|
||||
},
|
||||
|
|
|
@ -23,8 +23,10 @@ def timezone(ip):
|
|||
@hook.command("location")
|
||||
def geoip(inp, say = None, bot = None):
|
||||
".geoip <ip> - Performs a location check on the ip given."
|
||||
api = bot.config['api_keys']['geoip']
|
||||
give = find_location(inp, api)
|
||||
api_key = bot.config.get("api_keys", {}).get("geoip", None)
|
||||
if api_key is None:
|
||||
return "error: no api key set"
|
||||
give = find_location(inp, api_key)
|
||||
if give["country"] not in [""," ","-"," - "]:
|
||||
if give["state"] == give["city"]:
|
||||
localstring = give["city"]
|
||||
|
|
|
@ -22,6 +22,8 @@ def tiny(url, user, apikey):
|
|||
@hook.command
|
||||
def shorten(inp, bot = None):
|
||||
".shorten <url> - Makes an j.mp/bit.ly shortlink to the url provided"
|
||||
user = bot.config['api_keys']['bitly_user']
|
||||
api = bot.config['api_keys']['bitly_api']
|
||||
return tiny(inp, user, api)
|
||||
api_user = bot.config.get("api_keys", {}).get("bitly_user", None)
|
||||
api_key = bot.config.get("api_keys", {}).get("bitly_api", None)
|
||||
if api_key is None:
|
||||
return "error: no api key set"
|
||||
return tiny(inp, api_user, api_key)
|
||||
|
|
|
@ -25,7 +25,7 @@ def get_zipped_xml(*args, **kwargs):
|
|||
return etree.parse(ZipFile(zip_buffer, "r").open(path))
|
||||
|
||||
|
||||
def get_episodes_for_series(seriesname):
|
||||
def get_episodes_for_series(seriesname, api_key):
|
||||
res = {"error": None, "ended": False, "episodes": None, "name": None}
|
||||
# http://thetvdb.com/wiki/index.php/API:GetSeries
|
||||
try:
|
||||
|
@ -59,7 +59,7 @@ def get_episodes_for_series(seriesname):
|
|||
return res
|
||||
|
||||
|
||||
def get_episode_info(episode):
|
||||
def get_episode_info(episode, api_key):
|
||||
first_aired = episode.findtext("FirstAired")
|
||||
|
||||
try:
|
||||
|
@ -84,9 +84,13 @@ def get_episode_info(episode):
|
|||
|
||||
@hook.command
|
||||
@hook.command('tv')
|
||||
def tv_next(inp):
|
||||
def tv_next(inp, bot = None):
|
||||
".tv_next <series> -- get the next episode of <series>"
|
||||
episodes = get_episodes_for_series(inp)
|
||||
|
||||
api_key = bot.config.get("api_keys", {}).get("tvdb", None)
|
||||
if api_key is None:
|
||||
return "error: no api key set"
|
||||
episodes = get_episodes_for_series(inp, api_key)
|
||||
|
||||
if episodes["error"]:
|
||||
return episodes["error"]
|
||||
|
@ -102,7 +106,7 @@ def tv_next(inp):
|
|||
today = datetime.date.today()
|
||||
|
||||
for episode in reversed(episodes):
|
||||
ep_info = get_episode_info(episode)
|
||||
ep_info = get_episode_info(episode, api_key)
|
||||
|
||||
if ep_info is None:
|
||||
continue
|
||||
|
@ -130,9 +134,13 @@ def tv_next(inp):
|
|||
|
||||
@hook.command
|
||||
@hook.command('tv_prev')
|
||||
def tv_last(inp):
|
||||
def tv_last(inp, bot = None):
|
||||
".tv_last <series> -- gets the most recently aired episode of <series>"
|
||||
episodes = get_episodes_for_series(inp)
|
||||
|
||||
api_key = bot.config.get("api_keys", {}).get("tvdb", None)
|
||||
if api_key is None:
|
||||
return "error: no api key set"
|
||||
episodes = get_episodes_for_series(inp, api_key)
|
||||
|
||||
if episodes["error"]:
|
||||
return episodes["error"]
|
||||
|
@ -145,7 +153,7 @@ def tv_last(inp):
|
|||
today = datetime.date.today()
|
||||
|
||||
for episode in reversed(episodes):
|
||||
ep_info = get_episode_info(episode)
|
||||
ep_info = get_episode_info(episode, api_key)
|
||||
|
||||
if ep_info is None:
|
||||
continue
|
||||
|
|
|
@ -34,7 +34,7 @@ def wolframalpha(inp, bot=None):
|
|||
ret = '. '.join(pod_texts)
|
||||
|
||||
if not pod_texts:
|
||||
return 'no results'
|
||||
return 'No results.'
|
||||
|
||||
ret = re.sub(r'\\(.)', r'\1', ret)
|
||||
|
||||
|
@ -48,6 +48,6 @@ def wolframalpha(inp, bot=None):
|
|||
ret = re.sub(r'\W+$', '', ret) + '...'
|
||||
|
||||
if not ret:
|
||||
return 'no results'
|
||||
return 'No results.'
|
||||
|
||||
return ret
|
||||
|
|
Reference in a new issue