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' &
相关文档:
工具栏->高级->配置->编辑器显示->语法加亮->打开
在打开的文件中结尾加上下面文字,并保存。
/L10"Python" Line Comment = # Block Comment One = """ Block Comment Off = """ Escape Char = \ File Extensions = PY PYW
/Indent Strings = ":"
/Function String 1 = "%[ ,^t]++def[ ]+^([a-zA-Z0-9_] ......
使用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 增加行 ......
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') ......