From 8b1de13c8e1b7b709d7849f432b95acabecb42b0 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Tue, 25 Feb 2014 19:30:55 +1300 Subject: [PATCH] Added really shoddy, probably broken git plugin --- plugins/steam_calc.py | 1 - plugins/tvdb.py | 27 ++++----------------------- plugins/update.py | 40 ++++++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + 4 files changed, 45 insertions(+), 24 deletions(-) create mode 100644 plugins/update.py diff --git a/plugins/steam_calc.py b/plugins/steam_calc.py index b67ed88..6684eba 100644 --- a/plugins/steam_calc.py +++ b/plugins/steam_calc.py @@ -45,7 +45,6 @@ def steamcalc(inp, reply=None): else: name = inp.strip() - if force_reload: try: reply("Collecting data, this may take a while.") diff --git a/plugins/tvdb.py b/plugins/tvdb.py index 55914ca..b5fa12f 100644 --- a/plugins/tvdb.py +++ b/plugins/tvdb.py @@ -1,28 +1,10 @@ -""" -TV information, written by Lurchington 2010 -modified by rmmh 2010 -""" - import datetime -from urllib2 import URLError -from zipfile import ZipFile -from cStringIO import StringIO - -from lxml import etree from util import hook, http base_url = "http://thetvdb.com/api/" - - -def get_zipped_xml(*args, **kwargs): - try: - path = kwargs.pop("path") - except KeyError: - raise KeyError("must specify a path for the zipped file to be read") - zip_buffer = StringIO(http.get(*args, **kwargs)) - return etree.parse(ZipFile(zip_buffer, "r").open(path)) +api_key = "469B73127CA0C411" def get_episodes_for_series(series_name, api_key): @@ -30,7 +12,7 @@ def get_episodes_for_series(series_name, api_key): # http://thetvdb.com/wiki/index.php/API:GetSeries try: query = http.get_xml(base_url + 'GetSeries.php', seriesname=series_name) - except URLError: + except http.URLError: res["error"] = "error contacting thetvdb.com" return res @@ -43,9 +25,8 @@ def get_episodes_for_series(series_name, api_key): series_id = series_id[0] try: - series = get_zipped_xml(base_url + '%s/series/%s/all/en.zip' % - (api_key, series_id), path="en.xml") - except URLError: + series = http.get_xml(base_url + '%s/series/%s/all/en.xml' % (api_key, series_id)) + except http.URLError: res["error"] = "Error contacting thetvdb.com." return res diff --git a/plugins/update.py b/plugins/update.py new file mode 100644 index 0000000..13d9bed --- /dev/null +++ b/plugins/update.py @@ -0,0 +1,40 @@ +from git import Repo + + +from util import hook, web + +@hook.command +def update(inp, bot=None): + repo = Repo() + git = repo.git + pull = git.pull() + if "\n" in pull: + return web.haste(pull) + else: + return pull + + +@hook.command +def version(inp, bot=None): + repo = Repo() + + # get origin and fetch it + origin = repo.remotes.origin + info = origin.fetch() + + # get objects + head = repo.head + origin_head = info[0] + current_commit = head.commit + remote_commit = origin_head.commit + + if current_commit == remote_commit: + in_sync = True + else: + in_sync = False + + # output + return "Local {} is at commit {}, remote {} is at commit {}." \ + " You {} running the latest version.".format(head, current_commit.name_rev[:7], + origin_head, remote_commit.name_rev[:7], + "are" if in_sync else "are not") diff --git a/requirements.txt b/requirements.txt index d260437..ada6c3c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +GitPython==0.3.2.RC1 oauth2 pygeoip tweepy