Moar tweakage

This commit is contained in:
Luke Rogers 2012-05-17 11:52:31 +12:00
parent a2bfaf6ca5
commit 9c27f3ac06

View file

@ -6,6 +6,7 @@ import random
import re import re
from time import strftime, strptime from time import strftime, strptime
from datetime import datetime from datetime import datetime
from util.timesince import timesince from util.timesince import timesince
@ -46,8 +47,8 @@ def parseDateTime(s):
@hook.command @hook.command
def twitter(inp): def twitter(inp):
"twitter <user>/<user> <n>/<id>/#<hashtag>/@<user> -- Gets last/<n>th "\ "twitter <user>/<user> <n>/<id>/#<hashtag>/@<user> -- Gets last/<n>th " \
"tweet from <user>/gets tweet <id>/Gets random tweet with #<hashtag>/"\ "tweet from <user>/gets tweet <id>/Gets random tweet with #<hashtag>/" \
"gets replied tweet from @<user>." "gets replied tweet from @<user>."
def add_reply(reply_name, reply_id): def add_reply(reply_name, reply_id):
@ -104,25 +105,25 @@ def twitter(inp):
url = 'http://search.twitter.com/search.atom?q=%23' + inp[1:] url = 'http://search.twitter.com/search.atom?q=%23' + inp[1:]
searching_hashtag = True searching_hashtag = True
else: else:
return 'error: invalid request' return 'Error: Invalid request.'
try: try:
tweet = http.get_xml(url) tweet = http.get_xml(url)
except http.HTTPError as e: except http.HTTPError as e:
errors = {400: 'bad request (ratelimited?)', errors = {400: 'Bad request (ratelimited?)',
401: 'tweet is private', 401: 'Tweet is private',
403: 'tweet is private', 403: 'Tweet is private',
404: 'invalid user/id', 404: 'Invalid user/id',
500: 'twitter is broken', 500: 'Twitter is broken',
502: 'twitter is down ("getting upgraded")', 502: 'Twitter is down ("getting upgraded")',
503: 'twitter is overloaded (lol, RoR)'} 503: 'Twitter is overloaded'}
if e.code == 404: if e.code == 404:
return 'error: invalid ' + ['username', 'tweet id'][getting_id] return 'error: invalid ' + ['username', 'tweet id'][getting_id]
if e.code in errors: if e.code in errors:
return 'error: ' + errors[e.code] return 'Error: %s.' % errors[e.code]
return 'error: unknown %s' % e.code return 'Unknown Error: %s' % e.code
except http.URLError as e: except http.URLError as e:
return 'error: timeout' return 'Error: Request timed out.'
if searching_hashtag: if searching_hashtag:
ns = '{http://www.w3.org/2005/Atom}' ns = '{http://www.w3.org/2005/Atom}'