Skip to content

Instantly share code, notes, and snippets.

@gin0606
Created May 7, 2013 15:06
Show Gist options
  • Save gin0606/5533333 to your computer and use it in GitHub Desktop.
Save gin0606/5533333 to your computer and use it in GitHub Desktop.
今動くかは不明
#!/usr/local/bin/python
# -*- coding: utf-8; -*-
import re
from time import sleep
import datetime
import mechanize
from pyquery import PyQuery as pq
import PyRSS2Gen
login_id = ''
password = ''
trgt_root = "http://www.tumblr.com"
login_url = "/login"
target = "/dashboard"
pages = 5
def main():
br = mechanize.Browser()
br.set_handle_robots(False)
br.open(trgt_root + login_url)
try:
br.select_form(nr = 1)
br['email'] = login_id
br['password'] = password
br.submit()
except e:
print 'login failed' + e
posts = []
for i in range(pages):
page = br.open(trgt_root + target + (i == 0 and "" or "/%d" % i))
d = pq(page.read().decode('utf-8'))
posts += d('li.photo.not_mine')
sleep(2)
rss_items = []
for post in posts:
d = pq(post)
rss_items.append( PyRSS2Gen.RSSItem(
title = "Tumblr",
link = "%s" % d('a.permalink')[0].attrib['href'],
description = '<a href="%s"><img src="%s" alt="%s" /></a>' % (
d('a.permalink')[0].attrib['href'],
re.sub("_100", "_500", d("div.post_content img")[0].attrib['src']),
d('a.permalink')[0].attrib['title'],
),
guid = PyRSS2Gen.Guid( d('a.permalink')[0].attrib['href']),
pubDate = datetime.datetime.now(),))
rss = PyRSS2Gen.RSS2(
title = "Tumblr/dashboard",
link = trgt_root + target,
description = "Tumblr",
lastBuildDate = datetime.datetime.now(),
items = rss_items)
rss.write_xml(open("", "w+"), "utf-8")
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment