Skip to content

Instantly share code, notes, and snippets.

@md2
Created December 10, 2009 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save md2/253241 to your computer and use it in GitHub Desktop.
Save md2/253241 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from cookielib import CookieJar
from urllib2 import build_opener, HTTPCookieProcessor
from urllib import urlencode
import re
max_bookid = 173905
server1 = 'http://lib.rus.ec'
login1 = 'username'
password1 = 'password'
server2 = 'http://flibusta.net'
login2 = 'username'
password2 = 'password'
cj = CookieJar()
opener = build_opener(HTTPCookieProcessor(cj))
login_form = {'name': login1, 'pass': password1,
'persistent_login': 0,
'form_id': 'user_login'}
logged = re.compile('http://[^/]+/user/(\d+)$')
print "logging in to %s as %s:%s" % (server1, login1, password1)
url = opener.open('%s/user' % (server1), urlencode(login_form)).geturl()
try:
uid = logged.match(url).group(1)
except AttributeError:
print "oops, could not login!"
sys.exit(-1)
print "loading rates"
page = opener.open('%s/polka/show/%s' % (server1, uid)).read()
ratings = re.findall('<th>([1-5]) \(.*?\) .*? <a href=/b/(\d+)', page)
print len(ratings), "rated books"
cj.clear()
login_form.update({'name': login2, 'pass': password2})
print "logging in to %s as %s:%s" % (server2, login2, password2)
url = opener.open('%s/user' % (server2), urlencode(login_form)).geturl()
if not logged.match(url):
print "oops, could not login!"
sys.exit(-1)
print "copying rates"
for rate, bookid in ratings:
if int(bookid) < max_bookid:
opener.open('%s/tools/ajax?' % (server2) +
urlencode([('op', 'setrate'),
('b', bookid),
('r', rate)]))
print "bookid: %s, rate: %s" % (bookid, rate)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment