From d9324eaf959ebe7d0949c2897cc1f372430a1d2b Mon Sep 17 00:00:00 2001 From: Fletcher Boyd Date: Fri, 6 Sep 2013 14:12:21 +0800 Subject: [PATCH 01/16] bbcode style formatting. --- plugins/util/ircformat.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 plugins/util/ircformat.py diff --git a/plugins/util/ircformat.py b/plugins/util/ircformat.py new file mode 100644 index 0000000..6024564 --- /dev/null +++ b/plugins/util/ircformat.py @@ -0,0 +1,21 @@ +def bb(format_string): + rep = {'[b]':'\x02', + '[White]':'\x030', + '[Black]':'\x031', + '[dBlue]':'\x032', + '[dGreen]':'\x033', + '[dRed]':'\x034', + '[Brown]':'\x035', + '[Purple]':'\x036', + '[Gold]':'\x037', + 'Yellow':'\x038', + '[Green]':'\x039', + '[Cyan]':'\x0310', + '[lBlue]':'\x0311', + '[Blue]':'\x0312', + '[Pink]':'\x0313', + '[Gray]':'\x0314', + '[lGray]':'\x0315',} + for x in rep: + format_string = format_string.replace(x,rep[x]) + return format_string From 2103c64dd5a3cbab2f05b62016ce4e015673862f Mon Sep 17 00:00:00 2001 From: Fletcher Boyd Date: Fri, 6 Sep 2013 14:23:33 +0800 Subject: [PATCH 02/16] Added multiple code sets. Future proofed code set adding. --- plugins/util/ircformat.py | 41 ++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/plugins/util/ircformat.py b/plugins/util/ircformat.py index 6024564..1c9b0d9 100644 --- a/plugins/util/ircformat.py +++ b/plugins/util/ircformat.py @@ -1,21 +1,26 @@ def bb(format_string): - rep = {'[b]':'\x02', - '[White]':'\x030', - '[Black]':'\x031', - '[dBlue]':'\x032', - '[dGreen]':'\x033', - '[dRed]':'\x034', - '[Brown]':'\x035', - '[Purple]':'\x036', - '[Gold]':'\x037', - 'Yellow':'\x038', - '[Green]':'\x039', - '[Cyan]':'\x0310', - '[lBlue]':'\x0311', - '[Blue]':'\x0312', - '[Pink]':'\x0313', - '[Gray]':'\x0314', - '[lGray]':'\x0315',} - for x in rep: + stuff = {} + stuff['col'] = {'[white]':'\x030', + '[black]':'\x031', + '[dblue]':'\x032', + '[dgreen]':'\x033', + '[dred]':'\x034', + '[brown]':'\x035', + '[purple]':'\x036', + '[gold]':'\x037', + '[yellow]':'\x038', + '[green]':'\x039', + '[cyan]':'\x0310', + '[lblue]':'\x0311', + '[blue]':'\x0312', + '[pink]':'\x0313', + '[gray]':'\x0314', + '[lgray]':'\x0315',} + stuff['style'] = {'[b]':'\x02'} + stuff['sym'] = {'[point]':'\x07'} + final = {} + for x in stuff: + final.update(x) + for x in final: format_string = format_string.replace(x,rep[x]) return format_string From 14530f07f1fd5aa73f1dded620670ad52644ed0a Mon Sep 17 00:00:00 2001 From: Fletcher Boyd Date: Fri, 6 Sep 2013 14:54:50 +0800 Subject: [PATCH 03/16] Added text set. --- plugins/util/ircformat.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/util/ircformat.py b/plugins/util/ircformat.py index 1c9b0d9..a827dd3 100644 --- a/plugins/util/ircformat.py +++ b/plugins/util/ircformat.py @@ -18,6 +18,7 @@ def bb(format_string): '[lgray]':'\x0315',} stuff['style'] = {'[b]':'\x02'} stuff['sym'] = {'[point]':'\x07'} + stuff['text'] = {'[url]':'http://'} final = {} for x in stuff: final.update(x) From 07b5abff7bd8767ea1d8f2ac574beda600f62f86 Mon Sep 17 00:00:00 2001 From: Fletcher Boyd Date: Fri, 6 Sep 2013 14:57:26 +0800 Subject: [PATCH 04/16] bb moved to more descriptive rep. --- plugins/util/ircformat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/util/ircformat.py b/plugins/util/ircformat.py index a827dd3..5cd5444 100644 --- a/plugins/util/ircformat.py +++ b/plugins/util/ircformat.py @@ -1,4 +1,4 @@ -def bb(format_string): +def rep(format_string): stuff = {} stuff['col'] = {'[white]':'\x030', '[black]':'\x031', From 2fb0f811b85726ca91062b1a02ac7cc61dbe0621 Mon Sep 17 00:00:00 2001 From: Fletcher Boyd Date: Fri, 6 Sep 2013 14:59:07 +0800 Subject: [PATCH 05/16] Docstring and typo fix. --- plugins/util/ircformat.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/util/ircformat.py b/plugins/util/ircformat.py index 5cd5444..20f32d2 100644 --- a/plugins/util/ircformat.py +++ b/plugins/util/ircformat.py @@ -1,4 +1,5 @@ def rep(format_string): + """Replace based irc formatting""" stuff = {} stuff['col'] = {'[white]':'\x030', '[black]':'\x031', @@ -23,5 +24,5 @@ def rep(format_string): for x in stuff: final.update(x) for x in final: - format_string = format_string.replace(x,rep[x]) + format_string = format_string.replace(x,final[x]) return format_string From 5f87bf0e7624e9cd16a63587bfdd5c1af565cba4 Mon Sep 17 00:00:00 2001 From: Fletcher Boyd Date: Fri, 6 Sep 2013 15:06:00 +0800 Subject: [PATCH 06/16] Added base context styling. --- plugins/util/ircformat.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/util/ircformat.py b/plugins/util/ircformat.py index 20f32d2..9c21018 100644 --- a/plugins/util/ircformat.py +++ b/plugins/util/ircformat.py @@ -16,7 +16,9 @@ def rep(format_string): '[blue]':'\x0312', '[pink]':'\x0313', '[gray]':'\x0314', - '[lgray]':'\x0315',} + '[lgray]':'\x0315', + '[err]':'\x034\x02' + '[/err]':'\x030\x02'} stuff['style'] = {'[b]':'\x02'} stuff['sym'] = {'[point]':'\x07'} stuff['text'] = {'[url]':'http://'} @@ -26,3 +28,6 @@ def rep(format_string): for x in final: format_string = format_string.replace(x,final[x]) return format_string +def err(format_string): + """Format the string with standard error styling""" + return "\x034\x02{}\x030\x02".format(format_string) \ No newline at end of file From 75d4af13932c7bc8b8b6459febe577c3429e1847 Mon Sep 17 00:00:00 2001 From: Fletcher Boyd Date: Fri, 6 Sep 2013 15:10:39 +0800 Subject: [PATCH 07/16] ircformat.raw makes more sense with the addition of ircformat.err. --- plugins/util/ircformat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/util/ircformat.py b/plugins/util/ircformat.py index 9c21018..be5c400 100644 --- a/plugins/util/ircformat.py +++ b/plugins/util/ircformat.py @@ -1,4 +1,4 @@ -def rep(format_string): +def raw(format_string): """Replace based irc formatting""" stuff = {} stuff['col'] = {'[white]':'\x030', From d29b3c313f6ef52a6a14c009535064812ffe1462 Mon Sep 17 00:00:00 2001 From: Fletcher Boyd Date: Fri, 6 Sep 2013 15:40:08 +0800 Subject: [PATCH 08/16] Fixing dict.update() --- plugins/util/ircformat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/util/ircformat.py b/plugins/util/ircformat.py index be5c400..e08f291 100644 --- a/plugins/util/ircformat.py +++ b/plugins/util/ircformat.py @@ -24,7 +24,7 @@ def raw(format_string): stuff['text'] = {'[url]':'http://'} final = {} for x in stuff: - final.update(x) + final.update(stuff[x]) for x in final: format_string = format_string.replace(x,final[x]) return format_string From 893f621dd025febdd636f2349a37b35686aa98de Mon Sep 17 00:00:00 2001 From: Fletcher Boyd Date: Fri, 6 Sep 2013 16:10:48 +0800 Subject: [PATCH 09/16] Added clear, updated err. --- plugins/util/ircformat.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/util/ircformat.py b/plugins/util/ircformat.py index e08f291..442adf5 100644 --- a/plugins/util/ircformat.py +++ b/plugins/util/ircformat.py @@ -19,7 +19,8 @@ def raw(format_string): '[lgray]':'\x0315', '[err]':'\x034\x02' '[/err]':'\x030\x02'} - stuff['style'] = {'[b]':'\x02'} + stuff['style'] = {'[b]':'\x02', + '[clear]':'\x0f'} stuff['sym'] = {'[point]':'\x07'} stuff['text'] = {'[url]':'http://'} final = {} @@ -30,4 +31,4 @@ def raw(format_string): return format_string def err(format_string): """Format the string with standard error styling""" - return "\x034\x02{}\x030\x02".format(format_string) \ No newline at end of file + return "\x034\x02{}\x0f".format(format_string) \ No newline at end of file From 54d6453aa4cea3a308e4ee8c1557e70b03c3ee3b Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Fri, 6 Sep 2013 21:05:05 +1200 Subject: [PATCH 10/16] denoodleification --- plugins/namegen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/namegen.py b/plugins/namegen.py index 6e081c0..ff9a2f0 100755 --- a/plugins/namegen.py +++ b/plugins/namegen.py @@ -36,7 +36,7 @@ class NameGenerator(object): for name_part in name_parts: part = random.choice(self.parts[name_part]) - name = name.replace("{{}}".format(name_part), part) + name = name.replace("\{{}\}".format(name_part), part) return name From c2d021a07a5685888a45b6ba6f9eab9176fcb6bf Mon Sep 17 00:00:00 2001 From: Fletcher Boyd Date: Fri, 6 Sep 2013 17:06:52 +0800 Subject: [PATCH 11/16] better name. --- plugins/util/{ircformat.py => formatting.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename plugins/util/{ircformat.py => formatting.py} (100%) diff --git a/plugins/util/ircformat.py b/plugins/util/formatting.py similarity index 100% rename from plugins/util/ircformat.py rename to plugins/util/formatting.py From b40b4640d8a4114fb4fea8e7962ab7f37c31e5c7 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Sun, 8 Sep 2013 02:34:55 +1200 Subject: [PATCH 12/16] Added brand new steam_calc.py plugin --- plugins/steam.py | 130 ------------------------------------------ plugins/steam_calc.py | 80 ++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 130 deletions(-) create mode 100644 plugins/steam_calc.py diff --git a/plugins/steam.py b/plugins/steam.py index 2ec76cc..842a6cb 100644 --- a/plugins/steam.py +++ b/plugins/steam.py @@ -1,140 +1,10 @@ -import urllib2 import re -import json -from xml.dom import minidom from util import hook, http, web, text from bs4 import BeautifulSoup -db_ready = False - steam_re = (r'(.*:)//(store.steampowered.com)(:[0-9]+)?(.*)', re.I) -currencies = {'USD': 'us', 'euro1': "de", 'euro2': 'no', - 'pound': 'uk', 'rubles': 'ru', 'real': 'br', - 'yen': 'jp', 'dollars': 'us', 'german': 'de', - 'pounds': 'uk', 'russian': 'ru', 'brazil': 'br', - 'japan': 'jp', 'us': 'us', 'de': 'de', 'no': 'no', - 'uk': 'uk', 'ru': 'ru', 'br': 'br', 'jp': 'jp'} - - -def db_init(db): - db.execute("create table if not exists steam(nick primary key, acc)") - db.commit() - db_ready = True - - -def get_steam_info(name): - dom = minidom.parse(urllib2.urlopen(re.sub("{USER}", name, "http://steamcommunity.com/id/{USER}/?xml=1"))) - ID = int(dom.getElementsByTagName("steamID64")[0].firstChild.data) - key = bot.config.get("api_keys", {}).get("steam_key") - url = "http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key={}&steamid={}&format=json".format(key, - ID) - data = json.load(urllib2.urlopen(url)) - useable = data['response']['games'] - games = [] - played = [] - data = {} - playtime = 0 - for x in useable: - games.append(x) - if x['playtime_forever'] > 0: - played.append(x) - playtime += x['playtime_forever'] - played.sort(key=lambda x: x['playtime_forever']) - played.reverse() - data['playtime'] = int(playtime / 60.0) - data['played'] = played - data['games'] = games - data['%played'] = round(float(len(played)) / len(games) * 100, 2) - return data - - -@hook.command('sc', autohelp=False) -@hook.command(autohelp=False) -def steamcalc(inp, nick='', db=None): - """steamcalc [currency] - Gets value of steam account and - total hours played. Uses steamcommunity.com/id/. Uses - IRC nickname if none provided. """ - - if not db_ready: - db_init(db) - - currency = None - dontsave = False - if not inp: - user = db.execute("select acc from steam where nick=lower(?)", (nick,)).fetchone() - if not user: - inp = nick - else: - inp = user[0] - dontsave = True - else: - if len(inp.split(" ")) > 1: - if inp.split(" ")[1] in currencies: - currency = currencies[inp.split(" ")[1]] - dontsave = False - elif inp.split(" ")[1] == "dontsave": - dontsave = True - else: - return "Invalid currency!" - inp = inp.split(" ")[0] - if len(inp.split(" ")) > 2: - if inp.split(" ")[2] == "dontsave": - dontsave = True - - url = http.prepare_url("http://steamdb.info/calculator/", - {"player": inp, "currency": currency if currency else "us"}) - soup = http.get_soup(url) - - out = u"" - - try: - out += soup.findAll('h1', {'class': 'header-title'})[1].text.strip() - except Exception as e: - print e - return u"\x02Unable to retrieve info for {}!\x02 Is it a valid SteamCommunity profile username ({})? " \ - "Check if your profile is private, or go here to search: {}".format( - inp, web.try_isgd("http://steamcommunity.com/id/%s" % inp), web.try_isgd(url)) - - nextone = False - status = "Unknown" - for i in soup.findAll('td'): - if nextone: - status = i.text - break - elif i.text == "Status": - nextone = True - if status == "Online": - status = "\x033\x02Online\x02\x0f" - elif status == "Offline": - status = "\x034\x02Offline\x02\x0f" - elif status == "Away": - status = "\x038\x02Away\x02\x0f" - elif status == "Busy": - status = "\x035\x02Busy\x02\x0f" - elif "Looking to" in status: - status = "\x036\x02%s\x02\x0f" % status - out += " (%s)" % status - - for i in soup.findAll('div', {'class': 'panel'}): - if str(i.find('div', {'class': 'panel-heading'})) == '
Markdown
': - data = i - data = data.findAll('p')[1:] - print data - money = data[0].text.split(" ")[-1] - totalgames = data[1].text.split(" ")[-1] - time = data[2].text.split(" ")[-1].replace("h", "").replace(",", "") - time = str(int(round(float(time)))) - out += " This account is worth \x02{}\x02, and they've spent \x02{}\x02 hour(s) playing games! ".format(money, time) - out += "They have \x02{} games\x02 - {}".format(totalgames, web.try_isgd(url)) - - if not dontsave: - db.execute("insert or replace into steam(nick, acc) values (?,?)", (nick.lower(), inp)) - db.commit() - - return out - def get_steam_info(url): # we get the soup manually because the steam pages have some odd encoding troubles diff --git a/plugins/steam_calc.py b/plugins/steam_calc.py new file mode 100644 index 0000000..058494d --- /dev/null +++ b/plugins/steam_calc.py @@ -0,0 +1,80 @@ +from util import hook, http +import csv +import StringIO + +api_url = "http://mysteamgauge.com/user/{}.csv" +steam_api_url = "http://steamcommunity.com/id/{}/?xml=1" + + +def is_number(s): + try: + float(s) + return True + except ValueError: + return False + + +def unicode_dictreader(utf8_data, **kwargs): + csv_reader = csv.DictReader(utf8_data, **kwargs) + for row in csv_reader: + yield dict([(key, unicode(value, 'utf-8')) for key, value in row.iteritems()]) + + +@hook.command('sc') +@hook.command +def steamcalc(inp): + """steamcalc [currency] - Gets value of steam account and + total hours played. Uses steamcommunity.com/id/. """ + + name = inp.strip() + + try: + request = http.get(api_url.format(name)) + except (http.HTTPError, http.URLError): + return "Could not get data for {}!".format(name) + + csv_data = StringIO.StringIO(request) + reader = unicode_dictreader(csv_data) + + games = [] + for row in reader: + games.append(row) + + data = {} + + # basic information + steam_profile = http.get_xml(steam_api_url.format(name)) + data["name"] = steam_profile.find('steamID').text + + online_state = steam_profile.find('onlineState').text + data["state"] = online_state # will make this pretty later + + # work out the average metascore for all games + ms = [float(game["Metascore"]) for game in games if is_number(game["Metascore"])] + metascore = float(sum(ms))/len(ms) if len(ms) > 0 else float('nan') + data["average_metascore"] = "{0:.1f}".format(metascore) + + # work out the totals + data["games"] = len(games) + + total_value = sum([float(game["Value"]) for game in games if is_number(game["Value"])]) + data["value"] = str(int(round(total_value))) + + # work out the total size + total_size = 0.0 + + for game in games: + if not is_number(game["Size"]): + continue + + if game["Unit"] == "GB": + total_size += float(game["Size"]) + else: + total_size += float(game["Size"])/1024 + + data["size"] = "{0:.1f}".format(total_size) + + + return "{name} ({state}) has {games} games with a total value of ${value}" \ + " and a total size of {size}GB! The average metascore for these" \ + " games is {average_metascore}.".format(**data) From 63cf1f051469975c2142c395bb6fdc8f22857544 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Sun, 8 Sep 2013 02:37:47 +1200 Subject: [PATCH 13/16] few more comments --- plugins/steam_calc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/steam_calc.py b/plugins/steam_calc.py index 058494d..b98996f 100644 --- a/plugins/steam_calc.py +++ b/plugins/steam_calc.py @@ -33,9 +33,10 @@ def steamcalc(inp): except (http.HTTPError, http.URLError): return "Could not get data for {}!".format(name) - csv_data = StringIO.StringIO(request) + csv_data = StringIO.StringIO(request) # we use StringIO because CSV can't read a string reader = unicode_dictreader(csv_data) + # put the games in a list games = [] for row in reader: games.append(row) From 8ebf1e24ee6a5ebddc764f17f1867fce6a517aa2 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Sun, 8 Sep 2013 02:43:11 +1200 Subject: [PATCH 14/16] Those uppercase dict keys were annoying the hell out of me --- plugins/steam_calc.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/steam_calc.py b/plugins/steam_calc.py index b98996f..71cfa23 100644 --- a/plugins/steam_calc.py +++ b/plugins/steam_calc.py @@ -17,7 +17,7 @@ def is_number(s): def unicode_dictreader(utf8_data, **kwargs): csv_reader = csv.DictReader(utf8_data, **kwargs) for row in csv_reader: - yield dict([(key, unicode(value, 'utf-8')) for key, value in row.iteritems()]) + yield dict([(key.lower(), unicode(value, 'utf-8')) for key, value in row.iteritems()]) @hook.command('sc') @@ -51,27 +51,27 @@ def steamcalc(inp): data["state"] = online_state # will make this pretty later # work out the average metascore for all games - ms = [float(game["Metascore"]) for game in games if is_number(game["Metascore"])] + ms = [float(game["metascore"]) for game in games if is_number(game["metascore"])] metascore = float(sum(ms))/len(ms) if len(ms) > 0 else float('nan') data["average_metascore"] = "{0:.1f}".format(metascore) # work out the totals data["games"] = len(games) - total_value = sum([float(game["Value"]) for game in games if is_number(game["Value"])]) + total_value = sum([float(game["value"]) for game in games if is_number(game["value"])]) data["value"] = str(int(round(total_value))) # work out the total size total_size = 0.0 for game in games: - if not is_number(game["Size"]): + if not is_number(game["size"]): continue - if game["Unit"] == "GB": - total_size += float(game["Size"]) + if game["unit"] == "GB": + total_size += float(game["size"]) else: - total_size += float(game["Size"])/1024 + total_size += float(game["size"])/1024 data["size"] = "{0:.1f}".format(total_size) From 909306cfbe75325e060e6f5ec6d5c36c4069e6a3 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Sun, 8 Sep 2013 03:11:27 +1200 Subject: [PATCH 15/16] add temporary workaround for missing user issue --- plugins/steam_calc.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/steam_calc.py b/plugins/steam_calc.py index 71cfa23..cadf9e0 100644 --- a/plugins/steam_calc.py +++ b/plugins/steam_calc.py @@ -1,7 +1,10 @@ from util import hook, http import csv +import time import StringIO +gauge_url = "http://www.mysteamgauge.com/search?username={}" + api_url = "http://mysteamgauge.com/user/{}.csv" steam_api_url = "http://steamcommunity.com/id/{}/?xml=1" @@ -29,9 +32,10 @@ def steamcalc(inp): name = inp.strip() try: + http.get(gauge_url.format(name)) request = http.get(api_url.format(name)) except (http.HTTPError, http.URLError): - return "Could not get data for {}!".format(name) + return "Could not get data for this user." csv_data = StringIO.StringIO(request) # we use StringIO because CSV can't read a string reader = unicode_dictreader(csv_data) @@ -47,8 +51,8 @@ def steamcalc(inp): steam_profile = http.get_xml(steam_api_url.format(name)) data["name"] = steam_profile.find('steamID').text - online_state = steam_profile.find('onlineState').text - data["state"] = online_state # will make this pretty later + online_state = steam_profile.find('stateMessage').text + data["state"] = online_state.replace("
", ": ") # will make this pretty later # work out the average metascore for all games ms = [float(game["metascore"]) for game in games if is_number(game["metascore"])] From 143cd8dc96e113f57ddb214dea58169a18e667df Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Sun, 8 Sep 2013 03:26:34 +1200 Subject: [PATCH 16/16] bot restart needed. added support for timeouts to http.py, adjusted steam_calc timeout --- plugins/steam_calc.py | 5 +++-- plugins/util/http.py | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/steam_calc.py b/plugins/steam_calc.py index cadf9e0..10d7f8a 100644 --- a/plugins/steam_calc.py +++ b/plugins/steam_calc.py @@ -25,14 +25,15 @@ def unicode_dictreader(utf8_data, **kwargs): @hook.command('sc') @hook.command -def steamcalc(inp): +def steamcalc(inp, reply=None): """steamcalc [currency] - Gets value of steam account and total hours played. Uses steamcommunity.com/id/. """ name = inp.strip() try: - http.get(gauge_url.format(name)) + reply("Collecting data, this may take a few seconds.") + http.get(gauge_url.format(name), timeout=15, get_method='HEAD') request = http.get(api_url.format(name)) except (http.HTTPError, http.URLError): return "Could not get data for this user." diff --git a/plugins/util/http.py b/plugins/util/http.py index 4eccdf0..4409211 100755 --- a/plugins/util/http.py +++ b/plugins/util/http.py @@ -52,7 +52,7 @@ def get_json(*args, **kwargs): def open(url, query_params=None, user_agent=None, post_data=None, - referer=None, get_method=None, cookies=False, **kwargs): + referer=None, get_method=None, cookies=False, timeout=None, **kwargs): if query_params is None: query_params = {} @@ -78,7 +78,10 @@ def open(url, query_params=None, user_agent=None, post_data=None, else: opener = urllib2.build_opener() - return opener.open(request) + if timeout: + return opener.open(request, timeout=timeout) + else: + return opener.open(request) def prepare_url(url, queries):