Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Sunday, March 8, 2009

Python and Eventlet

http://wiki.secondlife.com/wiki/Eventlet/Documentation

Eventlet is an easy to use networking library written in Python. Eventlet is capable of supporting a large number of sockets per process by using nonblocking I/O, cooperatively multiplexing them through a single main loop. This approach allows for the implementation of massively concurrent servers which would require prohibitive amounts of memory under a traditional preemptive multi-threading or multi-process model. However, nonblocking I/O libraries such as asyncore or twisted can be difficult for programmers to use because they require the use of continuation passing style. This means code must be broken up into functions which initiate operations, and functions which will be called when the operation is complete, known as "callbacks."


Just use eventlet with a threads scanner to insert data to MySQL database.

Wednesday, February 25, 2009

Python will change my life

Year 2009, the world, the life, will be change. Trust me.

Monday, February 23, 2009

Generating and printing a range of ip addresses

Here's a generator function that works with two strings containing valid IP
addresses.
(Note: no error checking, such as verifying that endAddr > startAddr,
endAddr < 255.255.255.255, etc.)

def ipAddrRange(startAddr, endAddr):
def incrAddr(addrList):
addrList[3] += 1
for i in (3,2,1):
if addrList[i] == 256:
addrList[i] = 0
addrList[i-1] += 1

def asString(addrList):
return ".".join(map(str,addrList))

startAddrList = map(int,startAddr.split("."))
endAddrList = map(int,endAddr.split("."))

curAddrList = startAddrList[:]
yield asString(curAddrList)
for i in range(4):
while curAddrList[i] < endAddrList[i]:
incrAddr(curAddrList)
yield asString(curAddrList)

for addr in ipAddrRange("10.255.255.250","11.0.0.20"):
print addr

Wednesday, February 4, 2009

1ting.com音乐下载Python脚本

1ting.com 上的wma音乐是我觉得效果非常好的。所以写了个脚本。

wget http://scriptz.googlecode.com/svn/trunk/maesinfo-python/rsync-1ting.py

安装 pycurl 和 beautifulsoup ,设置 DOWNLOAD_DIR 就可以了~

如果发现不能下载,随时更新下脚本吧。或者提交个BUG。