2010-03-29

作者为 David Cramer | 访问插件主页

俺这是9时区设置,8时区的话,请自行修改

修改\themes\default\main.inc.

主要需要修改5个地方, today  yesterday  以及下面3个timestamp

[code lang=""]

<?
$day = '';
if (count($events))
{
$today = date('m d Y', time() - 54000);
$yesterday = date('m d Y', time() -140400);
if ($has_paging)
{
if ($has_prev_page) {
echo '<p><a href="' . $->get_previous_page_url($page) .

'">Newer Entries</a></p>';
}
}
?>
<table>
<?
foreach ($events as $event)
{
$timestamp = $event->get_date();
if ($today == date('m d Y', $timestamp -32400)) $this_day = $->__('Today');
else if ($yesterday == date('m d Y', $timestamp-32400)) $this_day = $->__('Yesterday');
else $this_day = $->__(ucfirst(htmlentities(date($->get_option('day_format'),

$timestamp-82400))));
if ($day != $this_day)
{
?>
<tr>
<th colspan="2">
<h2><? echo $this_day; ?></h2>
</th>
</tr>
<?
$day = $this_day;
}
..............
[/code]

Tags: ,,,,,.
2009-12-02

Sample screenshot

Karmasphere Studio for is a MapReduce development environment () based on NetBeans. It enables you to rapidly prototype jobs without the need for a , and to deploy, monitor and debug jobs on clusters or Amazon Elastic clusters, all from within a graphical desktop .

Tags: ,,,,,,.
2009-04-06

学了一周的python 写了这些应用,得到了几位大牛的帮助,在此不提名感谢啦~

实现效果:
一.以为中心散布出去
二.必须要有ssh
三.读取然后散布
四.目前可以散布到饭否,
五.可以借鉴散布到豆瓣广播
六.可以把饭否有人@你id 发消息提示回

现在已经成为主力 IM + 提醒 + 应用 了,只开的客户端即可,以为中心散布出去,有实时提醒功能,比如大家可以利用twitterfeed.com之类的来做一个rss的订阅提醒,或者自己写一个python的自动订阅更新提醒

待考虑功能:既然有就可以做出来一些功能
http://twitter.pbwiki.com/Bots
这有一些应用

前期准备
1.发消息到,需要 http://code.google.com/p/pyngfm/
2.需要python2.6以上版本 因为五 中 那个format代码实现的问题 lol 俺实在没啥好办法鸟

二.必须要有ssh
主要是用crontab的每隔多久执行一次程序的功能
我是用2分钟一次的,至今还没被饭否和封ip.
解决办法:
1.自己有机器挂着最好
2.如果有dreamhost账户的话,可以用dreamhost的ssh……不过小心被封……

四.发消息到饭否的代码
last.txt 需要手动建立,然后编辑添加某条消息的id值 这样以后更新只会更新至此,然后把最新的id写入last.txt

#!/usr/bin/python
from .dom.minidom import parseString
import urllib2
import urllib
import sys
def post_to_fanfou(msg):
    url = 'http://.fanfou.com/statuses/update.'
    data = urllib.urlencode({'status':msg})
    req = urllib2.Request(url,data)
    username = 'jimey'
    password = 'password'
    passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
    passman.add_password(None, url, username, password)
    authhandler = urllib2.HTTPBasicAuthHandler(passman)
    opener = urllib2.build_opener(authhandler)
    urllib2.install_opener(opener)
    response = urllib2.urlopen(req)
def main():
    f = open('last.txt','r')
    maxid = int(f.read())
    f.close()
    if maxid < 1166717326:
        print 'error'
        sys.exit(-1)
    params = urllib.urlencode({'since_id':maxid})
    url = ";http://.com/statuses/user_timeline/jimey.?%s";
    username = 'jimey'
    password = 'password'
    passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
    passman.add_password(None, url, username, password)
    authhandler = urllib2.HTTPBasicAuthHandler(passman)
    opener = urllib2.build_opener(authhandler)
    urllib2.install_opener(opener)
    f = urllib2.urlopen(url % params)
    xmltext = f.read()
    dom = parseString(xmltext)
    statuses = dom.childNodes[0]
    messages = []
    s = 0
    for node in statuses.childNodes:
        if node.nodeName == 'status':
            status = node
            for snode in status.childNodes:
                if snode.nodeName == 'id':
                    n = int(snode.childNodes[0].nodeValue)
                    if n > maxid:
                        maxid = n
                elif snode.nodeName == 'text' and snode.childNodes[0].nodeValue[0:2] != 'RT' and snode.childNodes[0].nodeValue[0] != '@':
                    messages.append(snode.childNodes[0].nodeValue.encode('utf-8'))
    while len(messages) > 0:
        post_to_fanfou(messages.pop())
        s = s + 1
    f = open('last.txt','w')
    f.write(str(maxid))
    f.close()
if __name__ == ";__main__";:
    main() 

四.2 发消息到饭否+的代码

需要在申请2个 KEY  分别是

pfm.setApiKey(‘************************’)  = Application Key

pfm.setUserAppKey(‘*********************************’) = own Application Key.

#!/usr/bin/python
from .dom.minidom import parseString
import urllib2
import urllib
import sys
from pyngfm import PyngFM 

def post_to_fanfou(msg):
    pfm = PyngFM() 

    pfm.setApiKey('************************')
    pfm.setUserAppKey('*********************************') 

    pfm.user_post('default','%s'%msg)
    url = 'http://.fanfou.com/statuses/update.'
    data = urllib.urlencode({'status':msg})
    req = urllib2.Request(url,data)
    username = 'jimey'
    password = 'password'
    passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
    passman.add_password(None, url, username, password)
    authhandler = urllib2.HTTPBasicAuthHandler(passman)
    opener = urllib2.build_opener(authhandler)
    urllib2.install_opener(opener)
    response = urllib2.urlopen(req)
def main():
    f = open('last.txt','r')
    maxid = int(f.read())
    f.close()
    if maxid < 1166717326:
        print 'error'
        sys.exit(-1)
    params = urllib.urlencode({'since_id':maxid})
    url = ";http://.com/statuses/user_timeline/jimey.?%s";
    username = 'jimey'
    password = 'password'
    passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
    passman.add_password(None, url, username, password)
    authhandler = urllib2.HTTPBasicAuthHandler(passman)
    opener = urllib2.build_opener(authhandler)
    urllib2.install_opener(opener)
    f = urllib2.urlopen(url % params)
    xmltext = f.read()
    dom = parseString(xmltext)
    statuses = dom.childNodes[0]
    messages = []
    s = 0
    for node in statuses.childNodes:
        if node.nodeName == 'status':
            status = node
            for snode in status.childNodes:
                if snode.nodeName == 'id':
                    n = int(snode.childNodes[0].nodeValue)
                    if n > maxid:
                        maxid = n
                elif snode.nodeName == 'text' and snode.childNodes[0].nodeValue[0:2] != 'RT' and snode.childNodes[0].nodeValue[0] != '@':
                    messages.append(snode.childNodes[0].nodeValue.encode('utf-8'))
    while len(messages) > 0:
        post_to_fanfou(messages.pop())
        s = s + 1
    f = open('last.txt','w')
    f.write(str(maxid))
    f.close()
if __name__ == ";__main__";:
    main() 

五 . 发消息到豆瓣广播

http://www.douban.com/group/topic/4604950/

六.如果有人在饭否回复你,在注册个马甲帐号然后把饭否回复人的id和饭否回复的内容一块发到去,由于你真身帐号已经加了这个马甲帐号的好友,所以在那马甲帐号发消息的时候会有 @饭否id  如果你饭否id和的id是一样的话,比如我用twhirl会有声音提示,如果含有@id 这样的消息出现的话

#!/usr/bin/python2.6
# -*- coding: utf-8 -*-
'''
Created on 2009-4-2
@author: jimey
'''
from .dom.minidom import parseString
import urllib2
import urllib
import sys
import 
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
def main():
    f = open('/home/jimey/fanfou/fanfoulast.txt','r')
    maxid = str(f.read())
    params = urllib.urlencode({'since_id':maxid})
    url = ";http://.fanfou.com/statuses/replies.?%s";
    username = 'jimey'
    password = 'password'
    passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
    passman.add_password(None, url, username, password)
    authhandler = urllib2.HTTPBasicAuthHandler(passman)
    opener = urllib2.build_opener(authhandler)
    urllib2.install_opener(opener)
    f = urllib2.urlopen(url % params)
    xmltext = f.read()
    dom = parseString(xmltext)
    statuses = dom.childNodes[0]
    id = []
    messages = []
    name = []
    content = []
    for node in statuses.childNodes:
        if node.nodeName == 'status':
            status = node
            for snode in status.childNodes:
                if snode.nodeName == 'id':
                   id.append(snode.childNodes[0].nodeValue)
                elif snode.nodeName == 'text':
                    messages.append(snode.childNodes[0].nodeValue)
                elif snode.nodeName == 'user':
                   for unode in snode.childNodes:
                     if unode.nodeName == 'name':
                          name.append(unode.childNodes[0].nodeValue)
    for q, a in zip(name,messages):
      content.append('{0} says {1}'.format(q,a))
    while len(content) > 0:
        = .(username='jimeybot', password='password')
       status = .PostUpdate(";%s"; %content.pop())
       f = open('fanfoulast.txt','w')
       print id
       maxid = id[0]
       f.write(str(maxid))
       f.close()
if __name__ == ";__main__";:
    main() 
Tags: ,,,,,,,,,,,,.
2009-04-02

利用饭否以及制作该脚本

首先前期准备工作

使用python2.6版本

Install Python 2.6 in Ubuntu

At first blush, it would seem that those wanting the latest stable python, 2.6, would have to compile it themselves (or so python.org would indicate). Fortunately for us, that process, which is at best annoying, and at worst long and complicated, is spared us by our friends over at Launchpad, and their "Personal Package Archives".

In order to install anything from the PPA, you need to add them to your repositories: "deb http://ppa.launchpad.net/doko/ubuntu/ intrepid main"

For those who’ve forgotten how, or just need a refresher, hit this page for full instructions.

Once you’ve done that, just run

sudo apt-get updatesudo apt-get install python2.6

编辑/etc/apt/source.list 把那个ppa的源加进去就好 注意,该安装只是纯粹的安装,不会删除原有的python2.5版本

运行的时候也需要运行python2.6才可,所以在下面的脚本中是 #!/usr/bin/python2.6

安装simplejson-2.0.9.tar.gz

安装 for python

http://code.google.com/p/python-twitter/

在安装的时候,如果是linux版,注意修改ez_setup.py,修改

DEFAULT_VERSION = "0.6c7"

中的0.6c7为0.6c9 否则 在python2.6 setup.py build

python2.6 setup.py install 中会提示无法下载

http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c7-py2.6.egg

实际上是因为该tool已经更新至

http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c9-py2.6.egg

修改之后安装顺利完成

然后安装 for python

如果想测试是否安装成功

可以在terminal中输入python2.6

>> import

>> import

如果没提示错误,则说明安装成功

>> import

的时候会有一提示

.py:12: DeprecationWarning: the md5 module is deprecated; use hashlib instead

在查 http://docs.python.org/library/md5.html 

Deprecated since version 2.5: Use the hashlib module instead.

该错误无视即可

至于为何要使用python2.6

是因为我脚本中用了

content.append(‘{0} says {1}’.format(q,a))

这个format只有在python2.6之后才有效果

目的是为了把在饭否上回复我的人的name和内容合并一块再发消息给我

中间编码unicode anscii转码的问题,耽误了很久时间

可能是linux的sys.defaultencoding 是 anscii

而windows也许会智能根据网页内容调整为utf-8??

我只能这么猜测了,目前win linux下都运行正常

关于unicode anscii的python编码问题

可以参考

http://bbs.ujn.edu.cn/showthread.php?threadid=251448

 

# 在上建立一个马甲帐号,用来发饭否上抓到有人发给我饭否帐号的回复的时候,把回复人的id以及回复内容,转发到,这样我的主力帐号就可以看到马甲帐号发的内容并且有提示,这样就可以及时回复饭否上的回复

至于如何及时回复… 可以利用来中转即可,即发一个有明显特征的前缀比如fanfou @饭否某人id 内容 把该内容发给的马甲帐号即可,用direct message or @马甲 之类的方式应该是都可以的。该脚本待下次有空再写。因为饭否上貌似回复俺的人不多=,=!! 脚本依然是用crontab上运行,每隔2分钟一次,希望不会被饭否封掉ip,这么频繁的打开那个页面 =,=!! 不过应该是有过滤不用很怕,至少 2分钟运行一次都没什么问题

#!/usr/bin/python2.6
# -*- coding: utf-8 -*-
'''
Created on 2009-4-2

@author: jimey
'''

from .dom.minidom import parseString
import urllib2
import urllib
import sys
import 
import sys
reload(sys)
sys.setdefaultencoding('utf-8')

def main():
    f = open('/home/jimey/fanfou/fanfoulast.txt','r')
    maxid = str(f.read())
    params = urllib.urlencode({'since_id':maxid})
    url = "http://.fanfou.com/statuses/replies.?%s"
    username = 'jimey'
    password = 'password'

    passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
    passman.add_password(None, url, username, password)

    authhandler = urllib2.HTTPBasicAuthHandler(passman)
    opener = urllib2.build_opener(authhandler)
    urllib2.install_opener(opener)
    f = urllib2.urlopen(url % params)
    xmltext = f.read()
    dom = parseString(xmltext)
    statuses = dom.childNodes[0]
    id = []
    messages = []
    name = []
    content = []
    for node in statuses.childNodes:
        if node.nodeName == 'status':
            status = node
            for snode in status.childNodes:
                if snode.nodeName == 'id':
                   id.append(snode.childNodes[0].nodeValue)
                elif snode.nodeName == 'text':
                    messages.append(snode.childNodes[0].nodeValue)
                elif snode.nodeName == 'user':
                   for unode in snode.childNodes:
                     if unode.nodeName == 'name':
                          name.append(unode.childNodes[0].nodeValue)
    for q, a in zip(name,messages):
      content.append('{0} says {1}'.format(q,a))
    while len(content) > 0:
        = .(username='jimeybot', password='password')
       status = .PostUpdate("%s" %content.pop())
       f = open('fanfoulast.txt','w')
       print id
       maxid = id[0]
       f.write(str(maxid))
       f.close()

if __name__ == "__main__":
    main()

windows下支援的代码

'''
Created on 2009-4-2

@author: jimey
'''

from .dom.minidom import parseString
import urllib2
import urllib
import sys
import 

def main():
    f = open('fanfoulast.txt','r')
    maxid = str(f.read())
    params = urllib.urlencode({'since_id':maxid})
    url = "http://.fanfou.com/statuses/replies.?%s"
    username = 'jimey'
    password = 'password'

    passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
    passman.add_password(None, url, username, password)

    authhandler = urllib2.HTTPBasicAuthHandler(passman)
    opener = urllib2.build_opener(authhandler)
    urllib2.install_opener(opener)
    f = urllib2.urlopen(url % params)
    xmltext = f.read()
    dom = parseString(xmltext)
    statuses = dom.childNodes[0]
    id = []
    messages = []
    name = []
    content = []
    s = 0
    for node in statuses.childNodes:
        if node.nodeName == 'status':
            status = node
            for snode in status.childNodes:
                if snode.nodeName == 'id':
                   id.append(snode.childNodes[0].nodeValue)
                elif snode.nodeName == 'text':
                    messages.append(snode.childNodes[0].nodeValue)
                elif snode.nodeName == 'user':
                   for unode in snode.childNodes:
                     if unode.nodeName == 'name':
                          name.append(unode.childNodes[0].nodeValue)
    for q, a in zip(name,messages):
      content.append('{0} says {1}'.format(q,a))
    while len(content) > 0:
        = .(username='jimeybot', password='password')
       status = .PostUpdate("%s" %content.pop())
       f = open('fanfoulast.txt','w')
       print id
       maxid = id[0]
       f.write(str(maxid))
       f.close()
       s += 1
    print "post to  %d posts" %s
if __name__ == "__main__":
    main()
Tags: ,,,,,,,,,,,.
2009-04-01

基本上还是之前的代码同步twitter到饭否

稍微修改了下的认证部分

再次感谢 raptium同学的Twitter 和饭否同步 代码

#!/usr/bin/python

from .dom.minidom import parseString
import urllib2
import urllib
import sys

def post_to_fanfou(msg):
    url = 'http://.fanfou.com/statuses/update.'
    data = urllib.urlencode({'status':msg})
    req = urllib2.Request(url,data)
    username = 'jimey'
    password = 'password'

    passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
    passman.add_password(None, url, username, password)

    authhandler = urllib2.HTTPBasicAuthHandler(passman)
    opener = urllib2.build_opener(authhandler)
    urllib2.install_opener(opener)
    response = urllib2.urlopen(req)

def main():
    f = open('last.txt','r')
    maxid = int(f.read())
    f.close()
    if maxid < 1166717326:
        print 'error'
        sys.exit(-1)

    params = urllib.urlencode({'since_id':maxid})
    url = "http://.com/statuses/user_timeline/jimey.?%s"
    username = 'jimey'
    password = 'password'

    passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
    passman.add_password(None, url, username, password)

    authhandler = urllib2.HTTPBasicAuthHandler(passman)
    opener = urllib2.build_opener(authhandler)
    urllib2.install_opener(opener)
    f = urllib2.urlopen(url % params)
    xmltext = f.read()
    dom = parseString(xmltext)
    statuses = dom.childNodes[0]
    messages = []
    s = 0
    for node in statuses.childNodes:
        if node.nodeName == 'status':
            status = node
            for snode in status.childNodes:
                if snode.nodeName == 'id':
                    n = int(snode.childNodes[0].nodeValue)
                    if n > maxid:
                        maxid = n
                elif snode.nodeName == 'text' and snode.childNodes[0].nodeValue[0:2] != 'RT' and snode.childNodes[0].nodeValue[0] != '@':
                    messages.append(snode.childNodes[0].nodeValue.encode('utf-8'))
    while len(messages) > 0:
        post_to_fanfou(messages.pop())
        s = s + 1
    f = open('last.txt','w')
    f.write(str(maxid))
    f.close()

if __name__ == "__main__":
    main()
Tags: ,,.
2009-03-31

在3.17那会 ftprush中调用unrar.exe

决定写一个auto unrar 的脚本

先是考虑glftpd,然后是那个seedbox 不过在看了资料之后都决定放弃,之后又陆陆续续忙其他事情

昨晚花了点时间,画了个流程图

早上8点半起来,开始写,写到中午基本上自动提示,手动下载torrent功能基本解决,下午上课到4点半,花了1小时时间写完全自动load torrent

修改了下的设置,具体看图,这样就不会出现提示,完全全自动了

Photobucket

最终用了脚本+批处理命令 解决所有问题

自动检测文件夹内100%解压rar分包并且删除文件的bat

脚本见此,不过稍微修正了一下。实现了一些自己需要判断写入的小功能

Tags: ,,,,,,.