This commit is contained in:
Luke Rogers 2013-10-01 11:53:15 +13:00
parent 651db7168f
commit 52f6260e1c

View file

@ -35,19 +35,18 @@ def reddit(inp):
# find the requested post number (if any) # find the requested post number (if any)
if len(parts) > 1: if len(parts) > 1:
subreddit = parts[0] url = base_url.format(parts[0].strip())
try: try:
id_num = int(parts[1]) - 1 id_num = int(parts[1]) - 1
except ValueError: except ValueError:
return "Invalid post number." return "Invalid post number."
else: else:
subreddit = parts[0] url = base_url.format(parts[0].strip())
else: else:
subreddit = "all" url = "http://reddit.com/.json"
try: try:
data = http.get_json(base_url.format(subreddit.strip()), data = http.get_json(url, user_agent=http.ua_chrome)
user_agent=http.ua_chrome)
except Exception as e: except Exception as e:
return "Error: " + str(e) return "Error: " + str(e)
data = data["data"]["children"] data = data["data"]["children"]
@ -74,9 +73,6 @@ def reddit(inp):
else: else:
item["warning"] = "" item["warning"] = ""
if not item["subreddit"]:
item["subreddit"] = subreddit
return u'\x02{title} : {subreddit}\x02 - posted by \x02{author}\x02' \ return u'\x02{title} : {subreddit}\x02 - posted by \x02{author}\x02' \
' {timesince} ago - {ups} upvotes, {downs} downvotes -' \ ' {timesince} ago - {ups} upvotes, {downs} downvotes -' \
' {link}{warning}'.format(**item) ' {link}{warning}'.format(**item)