比这篇新的文章: permutations(全排列)
比这篇旧的文章: 确认进程唯一,防止死掉

目前不成功的Twitter转校内日志工具

语言: Python, 标签: 无  2009/04/20发布 10个月前更新
作者: liufeng, 点击409次, 评论(0), 收藏者(0), , 打分:

背景
主题: 字体:
01 #!/usr/bin/env python
02 # -*- coding: utf-8 -*-
03
04 from xml.dom import minidom
05
06 # 需要先运行wget http://twitter.com/statuses/user_timeline/liufeng.xml
07 tw_url = 'http://twitter.com/statuses/user_timeline/liufeng.xml'
08 xmldoc = minidom.parse('liufeng.xml')
09
10 status = xmldoc.firstChild
11 tweet = status.childNodes[1]
12
13 output = ""
14 count = 1
15 flag = 0
16 for tweet in status.childNodes:
17     if flag == 1:
18         created_at = tweet.childNodes[1].firstChild.toxml()
19         text = tweet.childNodes[5].firstChild.toxml()
20         output += str(count) + " " + text + " " + created_at + "\n"
21         count += 1
22         flag = 0
23     else:
24         flag = 1
25
26
27 import cookielib
28 import urllib2
29 import urllib
30 import time
31
32 cj = cookielib.CookieJar()
33 opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
34 exheaders = [("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.1; Windows NT 5.1; SV1)"),]
35 opener.addheaders = exheaders
36 url_login = 'http://xiaonei.com/Login.do'
37 body = (('email', '*******@gmail.com'), ('password', '*******'))
38 req1 = opener.open(url_login, urllib.urlencode(body))
39 print "Login should be successful.\n"
40
41 body = {'relative_optype':'publisher', 'blogControl':'1'}
42 url_post = 'http://blog.xiaonei.com/NewEntry.do'
43 title = '最近我(说了/做了/想了)什么 %s' % time.asctime()
44 #xt = text.encode('utf-8')
45 print output
46 output = output.encode('utf-8')
47 print " fucked\n\n" + output
48 body['title'] = title
49 body['body'] = output
50 req2 = opener.open(url_post, urllib.urlencode(body))
51
52 #print urllib.urlencode(body)


所有评论,共0条:( 我也来说两句)


发表评论

注册登录后再发表评论