易截截图软件、单文件、免安装、纯绿色、仅160KB

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'            &


相关文档:

Python的字符串

Python中字符串被定义为引号之间的字符集合。Python支持使用成对的单引号或双引号,三引号包含的字符串。
使用索引操作符([])和切片操作符([:])可以得到子字符串。字符串有其特有的索引规则:第一个字符的索引是0
,最后一个字符的索引是-1。
加号(+)用于字符串连接运算,星号(*)则用于字符串重复。如下例:
pystr = " ......

Python在windows下的路径问题

    windows下的路径像“f:\program files\python\backup”其中“\”需要用转义符,写成“\\”,或者前面加r写成path
= r’f:\program files\python\backup’但是在调用一些系统命令,如os.system(rar a path e:\backup)会出错,原因是“program files&rdquo ......

配置vim 提高编写python脚本的效率

使用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 增加行 ......

【zz】Python常用资源网址

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 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号