Created
April 4, 2011 07:55
-
-
Save mopemope/901264 to your computer and use it in GitHub Desktop.
torumemo plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from plugpy.ext.skype import SkypePlugin, MissingPlugin | |
from eventlet.green import urllib2 | |
from pyquery import PyQuery as pq | |
import random | |
archive_url = "http://oldriver.org/torumemo/archive.html" | |
base_url = "http://oldriver.org/torumemo/" | |
def memo_list(): | |
urls = [] | |
conn = urllib2.urlopen(archive_url) | |
page = conn.read() | |
d = pq(page) | |
for anchor in d("a"): | |
href = pq(anchor).attr.href | |
if href and not href in ["index.html", "about.html"]: | |
urls.append(base_url + href) | |
return urls | |
def memo(url): | |
conn = urllib2.urlopen(url) | |
page = conn.read() | |
d = pq(page) | |
date = d(".date").text() | |
title = d(".title").text() | |
body = d(".body").text() | |
return date, title, body | |
class TorumemoPlugin(SkypePlugin): | |
alias = "#torumemo" | |
def __init__(self, *args, **kwargs): | |
self.urls = memo_list() | |
def on_message(self, *args): | |
url = random.choice(self.urls) | |
msg = "\n".join(memo(url)) | |
return msg | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment