Created
June 4, 2009 14:14
-
-
Save laiso/123644 to your computer and use it in GitHub Desktop.
wassr_follow_spam.py
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
#!/usr/bin/env python | |
# -*- coding: utf8 -*- | |
import re | |
import urllib, urllib2 | |
from lxml import etree | |
import simplejson | |
class WassrError(Exception): | |
pass | |
class Wassr: | |
username = '' | |
password = '' | |
channels ={} | |
def __init__(self, username=None, password=None): | |
try: | |
from pit import Pit | |
conf = Pit.get('wassr.jp', {'require': { | |
'login': 'login name', | |
'password': 'login password', | |
}}) | |
self.username = conf['login'] | |
self.password = conf['password'] | |
except: | |
if not username or not password: | |
raise WassrError('require your login name & password') | |
self.username = username | |
self.password = password | |
def getChannels(self): | |
uri = 'http://api.wassr.jp/channel_user/user_list.json?login_id=%s' % self.username | |
#res = urllib.urlopen(uri, {'account': self.username, 'password': self.password}).read() | |
req = urllib2.Request(uri) | |
data = urllib.urlencode({'account': self.username, 'password': self.password}) | |
res = urllib2.urlopen(req, data).read() | |
parsed = simplejson.decode(res) | |
return parsed['channels'] | |
def addFollower(self, name): | |
uri = 'http://api.wassr.jp/friendships/create/%s.json' % name | |
#req = urllib2.Request(uri) | |
data = urllib.urlencode({'account': self.username, 'password': self.password}) | |
res = urllib.urlopen(uri, data) | |
class WassrChannel: | |
def __init__(self): | |
pass | |
def fetchUsers(self, name, page=1): | |
uri = 'http://wassr.jp/channel/%s/users?page=%d' % (name, page) | |
res = urllib2.urlopen(uri) | |
et = etree.parse(res, parser=etree.HTMLParser()) | |
xpath = r'//div[@class="ChannelMemberList"]//span[@class="user-name"]/a' | |
users = [] | |
prog = re.compile(r'\/user\/(?P<name_en>.+)\/') | |
for name in et.getroot().xpath(xpath, namespace='http://www.w3.org/1999/xhtml'): | |
users.append(prog.match(name.get('href')).group('name_en')) | |
return users | |
if __name__ == "__main__": | |
wassr = Wassr() | |
channels = wassr.getChannels() | |
wc = WassrChannel() | |
for channel in channels: | |
users = wc.fetchUsers(channel['name_en']) | |
for user in users: | |
wassr.addFollower(user) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment