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

View File

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

View File

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

View File

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