Created
April 6, 2011 04:39
-
-
Save mopemope/905144 to your computer and use it in GitHub Desktop.
twitter search plugin
This file contains 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 SimpleSkypePlugin | |
import urllib2 | |
from urllib import quote_plus | |
from pyquery import PyQuery as pq | |
base_url = "http://search.twitter.com/search?q=%s&rpp=5&maxId=null&locale=ja" | |
def search(*args): | |
q = [] | |
word = " ".join(args) | |
word = word.encode("utf-8") | |
url = base_url % quote_plus(word) | |
conn = urllib2.urlopen(url) | |
page = conn.read() | |
d = pq(page) | |
for m in d(".msg"): | |
m = pq(m) | |
res = m.text() | |
q.append(res) | |
return q | |
class TwitterSearchPlugin(SimpleSkypePlugin): | |
alias = "#tw" | |
def on_message(self, *args): | |
q = search(*args) | |
if not q: | |
return "Not Found" | |
else: | |
return "\n\n".join(q) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment