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

之前写了一个自动解压压缩文件到压缩文件所在文件夹的脚本
后根据自己需要,写了另外两个。原理一样
都是使用winrar的命令
第一个脚本没考虑周到,只能解压rar文件
改进后可以支持winrar支持的各种文件
把指定文件夹下的文件保存到指定文件夹
#rardir.py
import os
import sys
src=sys.argv[1]
dst=sys.argv[2]
......

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_] ......

c语言模拟perl python中的数组负数索引

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;
}

......

Python 游戏初学

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