python实现twitter client
公司的代理可以直接穿墙,自由访问Twitter、Facebook等网站,这两天研究了一下Twitter提供的API,用python写了一个twitter client,只实现了基本功能,查看自己的twitter消息,也可以不验证,查看public的twitter消息。其他功能实现类似。主要函数如下:
def fetch_with_proxy(proxy, username, password, url):
proxy_handler = urllib2.ProxyHandler({"http" : proxy})
opener = urllib2.build_opener(proxy_handler)
urllib2.install_opener(opener)
authheader = AddAuthorizationHeader(username, password)
req = urllib2.Request(url)
try:
res = urllib2.urlopen(req)
except IOError, e:
if hasattr(e, 'code'):
if e.code != 401:
print e.code
else:
req.add_header("Authorization", authheader)
res = urllib2.urlopen(req)
data= simplejson.loads(res.read())
def AddAuthorizationHeader(username, password):
if username and password:
basic_auth = base64.encodestring('%s:%s' % (username, password))[:-1]
return 'Basic %s' % basic_auth
def main(user):
username='XXX@gmail.com' #change to your username and password
password='XXX'
proxy='host:port' &
相关文档:
http://code.google.com/p/shedskin/ Shed Skin 0.3 - support for 3 new standard library modules (now about 20 in total): - itertools (jeremie roquet) - heapq (jeremie roquet) - csv (converted using shedskin) - 4 new example programs (now 44 in total!): - maximum weighted matching al ......
能整理大部分无用文件
#!/usr/bin/python
#syscleaner.py
import os
import os.path
#delete files and directory recursively
def itedel(dir):
print('in dir :'+dir)
for doc in os.listdir(dir):
try:
if(os.path.isdir(doc)):
itedel(dir+'\\'+doc)
......
之前写了一个自动解压压缩文件到压缩文件所在文件夹的脚本
后根据自己需要,写了另外两个。原理一样
都是使用winrar的命令
第一个脚本没考虑周到,只能解压rar文件
改进后可以支持winrar支持的各种文件
把指定文件夹下的文件保存到指定文件夹
#rardir.py
import os
import sys
src=sys.argv[1]
dst=sys.argv[2]
......
http://blog.csdn.net/myan/archive/2008/01/07/2028545.aspx
http://blog.csdn.net/gashero/archive/2007/06/03/1636030.aspx
我感觉还是python应用更广一些,Ruby的RoR做Web框架好一些吧,至于perl,现在感觉实在有几分苦涩…… ......
zz from 《可爱的Python》
http://www.woodpecker.org.cn/
Python标准库 http://www.woodpecker.org.cn:9081/doc/Python/_html/PythonStandardLib/
简明Python教程 http://www.woodpecker.org.cn:9081/doc/abyteofpython_cn/chinese/index.html
Python快速介绍 http://www.zoomquiet.org/share/s5/intropy/070322-intro ......