只是突然有了这么个想法,于是花了差不多一天的时间把它架起来的。技术上使用了twisted+ajax,赞一下webfaction,twisted用起来很方便。
没有时间去ie调js的兼容啥的了,各位看官请自备Firefox或其它神器。
地址:http://www.zlovezl.cn/chatroom/
|
Sep
02
Type: 技术相关
|
|
只是突然有了这么个想法,于是花了差不多一天的时间把它架起来的。技术上使用了twisted+ajax,赞一下webfaction,twisted用起来很方便。 没有时间去ie调js的兼容啥的了,各位看官请自备Firefox或其它神器。 地址:http://www.zlovezl.cn/chatroom/ ...(Check the rest part) |
|
Views: (19) | Comments: (0)
|
|
Aug
23
Type: 技术相关
|
|
SNS什么的我是一直无爱的,这次蛋疼写了个登录开心网(kaixin001)并向所有好友发送站内消息的脚本。 开心网在登录的时候做了一些处理,并不传原始密码,从js分析到的结果是:登录时会生成一个随机的key,然后用这个key和原始密码进行xxtea加密,把加密后的结果再进行sha1加密。之后post这个key以及加密后的密码进行登录验证。 以下是很简陋的脚本内容:
#coding: utf-8
"""
开心网操作脚本
Author: piglei2007@gmail.com
Version: 1.0
"""
import re
import urllib
import urllib2
import random
import hashlib
import binascii
import cookielib
import simplejson
from xxtea import encrypt
LOGIN_URL = "http://www.kaixin001.com/login/login_api.php"
LOGIN_KEY_URL = "http://www.kaixin001.com/"
FRIEND_LIST_URL = "http://www.kaixin001.com/interface/suggestfriend.php"
MESSAGE_SEND_URL = "http://www.kaixin001.com/msg/post.php"
LOGIN_KEY_RE = re.compile(r"new\sEnLogin\('(.*?)'")
class LoginError(Exception):
"""
登录失败抛出异常
"""
class Kaixin001User(object):
"""
操作kaixin001,现有方法:
get_login_key - 获得用户访问登录页面时分配的加密key
get_rpassword - 获得经过xxtea以及sha1加密后的密码
login - 登录
get_friends_list - 获得所有好友,返回字典格式
send_messages_to_all - 给所有好友发消息
"""
def __init__(self, username, password):
self.username = username
self.password = password
self.cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj))
opener.addheaders = [
("User-agent", "Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.9.1) Gecko/20090704 Firefox/3.5"),
("Accept", "*/*"),
("Host", "www.kaixin001.com")
]
urllib2.install_opener(opener)
def get_login_key(self):
"""
获得登录时候的加密key
"""
_temp = urllib2.urlopen(LOGIN_KEY_URL).read()
key = LOGIN_KEY_RE.search(_temp).group(1)
return key
def login(self):
"""
登录
"""
login_key = self.get_login_key()
rpassword = self.get_rpassword(self.password, login_key)
login_params = {
'email': self.username,
'encypt': login_key,
'rpasswd': rpassword,
'url': '/home/',
'ver': '1'
}
req = urllib2.Request(LOGIN_URL, urllib.urlencode(login_params), {
"Referer": "http://www.kaixin001.com/"
})
result = urllib2.urlopen(req).read()
# 登录失败
if "errno" in result:
raise LoginError("登录失败,请检查用户名或密码")
print "用户 %s 登录成功!" % self.username
return 'ok'
def get_friends_list(self):
"""
获得所有好友列表
"""
get_friends_params = {
't': str(random.random()),
'type': 'all',
}
result = urllib2.urlopen(FRIEND_LIST_URL, urllib.urlencode(get_friends_params)).read()
friends = simplejson.loads(result)
print "你一共有 %s 位好友" % (len(friends) - 1)
return friends
def send_messages_to_all(self, message=''):
"""
给所有好友发消息
"""
friends = self.get_friends_list()
send_params = {
'attachment_cancel': '',
'attachment_forwarding': '',
'attachment_random': '',
'code': '',
'content': message,
'forward_thread': '',
'rcode': '',
'service': '0',
'texttype': 'html',
'uids': ",".join([str(f['uid']) for f in friends])
}
result = urllib2.urlopen(MESSAGE_SEND_URL, urllib.urlencode(send_params))
print result.geturl()
print "消息发送成功"
return 'ok'
def get_rpassword(self, password, key):
"""
获得加密后的密码
"""
xxtea_pw = binascii.b2a_hex( encrypt(password, key) )
r_password = hashlib.sha1(xxtea_pw).hexdigest()
return r_password
if __name__ == '__main__':
kxu = Kaixin001User(
username = 'your_username',
password = 'your_password'
)
kxu.login()
kxu.send_messages_to_all("This message is send by Python.")
...(Check the rest part) |
|
Views: (80) | Comments: (2)
|
|
Aug
20
Type: 技术相关
|
|
最近在看《Python高级编程》,看到个让人会心一笑的例子,贴上来。
class MeanElephant(object):
def __init__(self):
self._people_to_kill = []
def is_slapped_on_the_butt_by(self, name):
self._people_to_kill.append(name)
print 'Ouch!'
def revenge(self):
print '10 year later...'
for people in self._people_to_kill:
print 'Me kill %s' % people
if __name__ == '__main__':
joe = MeanElephant()
joe.is_slapped_on_the_butt_by('Tarek')
joe.is_slapped_on_the_butt_by('Bill')
joe.revenge()
嘿嘿,挺有意思。 ...(Check the rest part) |
|
Views: (89) | Comments: (3)
|
|
Aug
08
Type: 杂七杂八
|
|
继上星期被奇辣无比的西瓜皮打败了之后,大家以为我就会这么妥协吗?不可能的,湖南人是不会向辣椒妥协的,于是乎这个周末,又屁颠屁颠的跑去吃东西啦。这次去的是之前在网上看到口碑很好的“湖南口味虾”,刚好周末准备去中山路附近逛街,于是正好这次顺路就去那边吃那的招牌菜:“口味虾”啦。地址在这个位置: 位置刚好是从百盛旁边的小路进去的中山小吃街,于是乎逛完百盛后,刚好去那边吃中饭。人还是挺多的,不过有位置,径直上了二楼,菜的价格还行,和老婆两个人一起点了一份小份口味虾,一份手撕包菜,一共30多。上菜的速度不错,10分钟左右菜就上来啦。 ...(Check the rest part) |
|
Views: (159) | Comments: (10)
|
|
Aug
07
Type: 技术相关
|
|
买了webfaction的主机以来一直用的都是sftp来上传东西,所以每次有一些小修改之类的都十分的麻烦。得先连到服务器,然后找到改了哪些文件,然后覆盖,然后重启。今早终于受不了这个折磨,花了点时间给这配上个svn。以后修改啥东西就方便多了,svn果然神器。 另最近两天给公司某产品架了个类似bbs的略微蛋疼的东西,和两个同事一起使用django开发了两天。我给这个东西取名“(豆瓣小组+百度贴吧)之合体山寨版”。地址在这。各位看客去玩玩吧,记得不要乱灌水哦^ ^。 |
|
Views: (106) | Comments: (2)
|