易截截图软件、单文件、免安装、纯绿色、仅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 = " ......

c盘整理 Python脚本

能整理大部分无用文件
#!/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)
......

python中正则表达式与re 模块

1. 9.7 正则表达式与 re 模块
一个正则表达式就是一个用来表示某种模式的字符串。它能帮助你方便的检查一个字符串是否与某种模式匹配。
re 模块使 Python 语言拥有全部的正则表达式功能。 compile 函数根据一个模式字符串和可选的标志参数生成一个正则表达式对象。该对象拥有一系列方法用于正则表达式匹配和替换。 re 模 ......

UltraEdit对Python的高亮显示

工具栏->高级->配置->编辑器显示->语法加亮->打开
在打开的文件中结尾加上下面文字,并保存。
/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_] ......

【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号