refactor vimeo plugin, PEP8

This commit is contained in:
Ryan Hitchman 2011-04-13 20:45:07 -05:00
parent 0ed4fcfff4
commit faa68b6af5
4 changed files with 19 additions and 31 deletions

View File

@ -4,20 +4,20 @@ from util import hook, http
@hook.command
def bam(inp):
".bam [basic|magic|heart|krugr] <message> -- creates a big ass message"
host = 'http://bigassmessage.com/'
path = 'BAM.php?'
params = {'action': 'SAVE', 'theStyle': 'basic', 'theMessage': inp}
if ' ' in inp:
style, message = inp.split(None, 1)
if style in ['basic', 'magic', 'heart', 'krugr']:
params['theStyle'] = style
params['theMessage'] = message
response = http.get_xml(host + path, params)
status = response.xpath('//status/text()')[0]
if status == 'ok':
return host + response.xpath('//msgid/text()')[0]
else:

View File

@ -12,11 +12,11 @@ def sieve_suite(bot, input, func, kind, args):
if kind == "command":
if input.trigger in bot.config.get('disabled_commands', []):
return None
ignored = bot.config.get('ignored', []);
if input.host in ignored or input.nick in ignored:
return None
fn = re.match(r'^plugins.(.+).py$', func._filename)
disabled = bot.config.get('disabled_plugins', [])
@ -39,5 +39,5 @@ def sieve_suite(bot, input, func, kind, args):
if input.host not in admins and input.nick not in admins:
return None
return input

View File

@ -138,7 +138,7 @@ def tv_last(inp):
ended = episodes["ended"]
episodes = episodes["episodes"]
prev_ep = None
prev_ep = None
today = datetime.date.today()
for episode in reversed(episodes):

View File

@ -1,27 +1,15 @@
from util import http,hook
import re
video_regex = (r'(?i)http://(?:www\.)?vimeo.com/([A-Za-z0-9\-]+)')
r'([a-zA-Z]+://|www\.)[^ ]+'
video_request_base = "http://vimeo.com/api/v2/video/%s.json"
from util import http,hook
video_info = "\x02%(title)s\x02 - length \x02%(duration)ss\x02 - \x02%(stats_number_of_likes)s\x02 likes - \x02%(stats_number_of_plays)s\x02 plays - \x02%(user_name)s\x02 on \x02%(upload_date)s\x02"
@hook.regex(r'vimeo.com/([0-9]+)')
def vimeo_url(match):
info = http.get_json('http://vimeo.com/api/v2/video/%s.json'
% match.group(1))
def viemo_video_info(video_id):
json_url = video_request_base % (video_id,)
json_responses = http.get_json(json_url)
if json_responses:
video_details = json_responses[0]
return video_info % video_details
@hook.regex(video_regex)
def viemo_url(url_match):
return viemo_video_info(url_match.group(1))
if info:
return ("\x02%(title)s\x02 - length \x02%(duration)ss\x02 - "
"\x02%(stats_number_of_likes)s\x02 likes - "
"\x02%(stats_number_of_plays)s\x02 plays - "
"\x02%(user_name)s\x02 on \x02%(upload_date)s\x02"
% info[0])