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://purpen.javaeye.com/blog/98095
python 执行系统命令比较
关键字: python os system 系统命令
在此比较一下两种方法执行系统命令的方法,以方便于日后运用:(
1. os.system()
system(command) -> exit_status
Execute the  ......
使用python.vim使python代码高亮
http://www.vim.org/scripts/script.php?script_id=790
使用
Pydiction插件使vim增加tab代码提示功能
http://www.vim.org/scripts/script.php?script_id=850
具体安装方法可以参照帮助或者README,因为版本变化会导致安装方法上产生差异
编辑~/.vimrc文件增加下面选项
set nu 增加行 ......
int main()
{
int a[] = {1,2,3,4,5};
int i;
int * p = a;
for (p = a + 4, i = 0; i < 5; i++) {
printf("%d ",p[-i]);
}
return 0;
}
......
twisted是一个专门用于python的网络开发的框架。可以说是现在python中新的一支至力于发展高性能网络开发的框架,发展很稳定。
http://twistedmatrix.com/trac/
http://www-128.ibm.com/developerworks/cn/linux/network/l-twist/part1/index.html
http://wiki.woodpecker.org.cn/moin/PyTwisted ......
import sys, pygame, time
size = width, height = 700,700
fontColor = (0,0,255)
class walk:
'''This is a game about war.
Just like war 3.'''
def __init__(self):
'''Init the screen.
Get param and init the screen'''
#print ('this is init funnction') ......