Skip to content

Instantly share code, notes, and snippets.

@mopemope
Created April 4, 2011 07:55
Show Gist options
  • Save mopemope/901264 to your computer and use it in GitHub Desktop.
Save mopemope/901264 to your computer and use it in GitHub Desktop.
torumemo plugin
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