<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>phill84.org &#187; Programming</title>
	<atom:link href="http://phill84.org/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://phill84.org</link>
	<description>System.out.print</description>
	<lastBuildDate>Sat, 26 Mar 2011 10:21:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Correction of Listing 2-25 in Pro Javascript Techniques</title>
		<link>http://phill84.org/2011/03/correction-of-listing-2-25-in-pro-javascript-techniques/</link>
		<comments>http://phill84.org/2011/03/correction-of-listing-2-25-in-pro-javascript-techniques/#comments</comments>
		<pubDate>Tue, 08 Mar 2011 22:49:42 +0000</pubDate>
		<dc:creator>phill84</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[privileged method]]></category>

		<guid isPermaLink="false">http://phill84.org/?p=6257</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<pre class="brush: jscript; title: ; notranslate">function User(properties) {
        for (var i in properties) {
                (function(){
                        var key = i;
                        this['get' + key] = function() {
                                return properties[key];
                        };
                        this['set' + key] = function(val) {
                                properties[key];
                        };
                }).call(this);
        }
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://phill84.org/2011/03/correction-of-listing-2-25-in-pro-javascript-techniques/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Posting douban saying using python / 用python發送豆瓣廣播</title>
		<link>http://phill84.org/2010/01/posting-douban-saying-using-python-%e7%94%a8python%e7%99%bc%e9%80%81%e8%b1%86%e7%93%a3%e5%bb%a3%e6%92%ad/</link>
		<comments>http://phill84.org/2010/01/posting-douban-saying-using-python-%e7%94%a8python%e7%99%bc%e9%80%81%e8%b1%86%e7%93%a3%e5%bb%a3%e6%92%ad/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 10:48:18 +0000</pubDate>
		<dc:creator>phill84</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[douban]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[saying]]></category>
		<category><![CDATA[廣播]]></category>
		<category><![CDATA[豆瓣]]></category>

		<guid isPermaLink="false">http://phill84.org/2010/01/posting-douban-saying-using-python-%e7%94%a8python%e7%99%bc%e9%80%81%e8%b1%86%e7%93%a3%e5%bb%a3%e6%92%ad/</guid>
		<description><![CDATA[Finally I got sometime to work on implementing my own python script for posting douban saying, again. This time I used the library written by Leah Culver, and everything went smoothly. It&#8217;s just that I have no idea why douban &#8230; <a href="http://phill84.org/2010/01/posting-douban-saying-using-python-%e7%94%a8python%e7%99%bc%e9%80%81%e8%b1%86%e7%93%a3%e5%bb%a3%e6%92%ad/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Finally I got sometime to work on implementing my own python script for posting douban saying, again. This time I used the <a href="http://oauth.googlecode.com/svn/code/python/oauth/">library</a> written by <a href="http://leahculver.com/">Leah Culver</a>, and everything went smoothly. It&#8217;s just that I have no idea why douban chose to use a different signing algorithm(if a thing as stupid as it is can be called a algorithm) for requesting access token.</p>
<p>終於又有時間再一次捯鼓豆瓣. 這次在 <a href="http://leahculver.com/">Leah Culver</a> 寫的 <a href="http://oauth.googlecode.com/svn/code/python/oauth/">library</a> 的基礎上, 終於把python腳本發送豆瓣廣播終於搞定了. 唯一理解不能的事就是豆瓣在獲取access token的時候用了一個莫名其妙的簽名算法(如果這種也能叫做算法的話 = =).</p>
<p>Click on read more to view the actual code of the script.<br />
查看腳本內容請點擊 read more<br />
<span id="more-619"></span></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">binascii</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">cgi</span>
<span style="color: #ff7700;font-weight:bold;">import</span> hashlib
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">hmac</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">httplib</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">random</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib</span>
&nbsp;
SERVER  = <span style="color: #483d8b;">'api.douban.com'</span>
API_KEY = <span style="color: #483d8b;">'your api key'</span>
SECRET  = <span style="color: #483d8b;">'your api secret'</span>
&nbsp;
OAUTH_SERVER            = <span style="color: #483d8b;">'www.douban.com'</span>
REQUEST_TOKEN_URI       = <span style="color: #483d8b;">'/service/auth/request_token'</span>
AUTHORIZATION_URI       = <span style="color: #483d8b;">'/service/auth/authorize'</span>
ACCESS_TOKEN_URI        = <span style="color: #483d8b;">'/service/auth/access_token'</span>
SAYING_URI              = <span style="color: #483d8b;">'/miniblog/saying'</span>
&nbsp;
SIG_METHOD              = <span style="color: #483d8b;">'HMAC-SHA1'</span>
OAUTH_VER               = <span style="color: #483d8b;">'1.0'</span>
SCHEME                  = <span style="color: #483d8b;">'http'</span>
&nbsp;
ACCESS_TOKEN_FILE       = <span style="color: #483d8b;">'douban_access_token'</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> escape<span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #dc143c;">urllib</span>.<span style="color: black;">quote</span><span style="color: black;">&#40;</span>s, safe=<span style="color: #483d8b;">'~'</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> generate_timestamp<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">time</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> generate_nonce<span style="color: black;">&#40;</span>length=<span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">''</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">random</span>.<span style="color: black;">randint</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">9</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>length<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> normalize_params<span style="color: black;">&#40;</span>params<span style="color: black;">&#41;</span>:
        key_values = <span style="color: black;">&#91;</span><span style="color: black;">&#40;</span>escape<span style="color: black;">&#40;</span>k<span style="color: black;">&#41;</span>, escape<span style="color: black;">&#40;</span>v<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> k,v <span style="color: #ff7700;font-weight:bold;">in</span> params.<span style="color: black;">items</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
        key_values.<span style="color: black;">sort</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">'&amp;'</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'%s=%s'</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>k, v<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> k, v <span style="color: #ff7700;font-weight:bold;">in</span> key_values<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> sign<span style="color: black;">&#40;</span>method, url, params, secret, token_secret<span style="color: black;">&#41;</span>:
        sig = <span style="color: black;">&#40;</span>
                        escape<span style="color: black;">&#40;</span>method.<span style="color: black;">upper</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>,
                        escape<span style="color: black;">&#40;</span>SCHEME + <span style="color: #483d8b;">'://'</span> + url<span style="color: black;">&#41;</span>,
                        escape<span style="color: black;">&#40;</span>normalize_params<span style="color: black;">&#40;</span>params<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: black;">&#41;</span>
        key = escape<span style="color: black;">&#40;</span>secret<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">'&amp;'</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> url == OAUTH_SERVER + ACCESS_TOKEN_URI:
                <span style="color: #808080; font-style: italic;">#I have no idea why the fuck douban uses concatenated secrets as signature instead of the computed one</span>
                <span style="color: #ff7700;font-weight:bold;">return</span> secret + <span style="color: #483d8b;">'&amp;'</span> + token_secret
        <span style="color: #ff7700;font-weight:bold;">if</span> token_secret:
                key += escape<span style="color: black;">&#40;</span>token_secret<span style="color: black;">&#41;</span>
        base_string = <span style="color: #483d8b;">'&amp;'</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>sig<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #dc143c;">binascii</span>.<span style="color: black;">b2a_base64</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">hmac</span>.<span style="color: #dc143c;">new</span><span style="color: black;">&#40;</span>key, base_string, hashlib.<span style="color: black;">sha1</span><span style="color: black;">&#41;</span>.<span style="color: black;">digest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>:-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> generate_header<span style="color: black;">&#40;</span>method, url, params, key, <span style="color: #dc143c;">token</span><span style="color: black;">&#41;</span>:
        header = <span style="color: #483d8b;">'OAuth realm=&quot;&quot;'</span>
        params<span style="color: black;">&#91;</span><span style="color: #483d8b;">'oauth_version'</span><span style="color: black;">&#93;</span> = OAUTH_VER
        signature = sign<span style="color: black;">&#40;</span>method, url, params, key, <span style="color: #dc143c;">token</span><span style="color: black;">&#41;</span>
        params<span style="color: black;">&#91;</span><span style="color: #483d8b;">'oauth_signature'</span><span style="color: black;">&#93;</span> = signature
        key_values = <span style="color: black;">&#91;</span><span style="color: black;">&#40;</span>k, v<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> k,v <span style="color: #ff7700;font-weight:bold;">in</span> params.<span style="color: black;">items</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
        key_values.<span style="color: black;">sort</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">for</span> k, v <span style="color: #ff7700;font-weight:bold;">in</span> key_values:
                header += <span style="color: #483d8b;">', %s=&quot;%s&quot;'</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>k, escape<span style="color: black;">&#40;</span>v<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#123;</span><span style="color: #483d8b;">&quot;Authorization&quot;</span>: header<span style="color: black;">&#125;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> create_connection<span style="color: black;">&#40;</span>server<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #dc143c;">httplib</span>.<span style="color: black;">HTTPConnection</span><span style="color: black;">&#40;</span>server<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> read_access_token_file<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">access</span><span style="color: black;">&#40;</span>ACCESS_TOKEN_FILE, <span style="color: #dc143c;">os</span>.<span style="color: black;">F_OK</span><span style="color: black;">&#41;</span>:
                token_file = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>ACCESS_TOKEN_FILE, <span style="color: #483d8b;">'r'</span><span style="color: black;">&#41;</span>
                data = token_file.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                data = <span style="color: #dc143c;">cgi</span>.<span style="color: black;">parse_qs</span><span style="color: black;">&#40;</span>data, keep_blank_values=<span style="color: #008000;">False</span><span style="color: black;">&#41;</span>
                <span style="color: #dc143c;">token</span> = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>
                <span style="color: #ff7700;font-weight:bold;">for</span> k, v <span style="color: #ff7700;font-weight:bold;">in</span> data.<span style="color: black;">iteritems</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
                        <span style="color: #dc143c;">token</span><span style="color: black;">&#91;</span>k<span style="color: black;">&#93;</span> = <span style="color: #dc143c;">urllib</span>.<span style="color: black;">unquote</span><span style="color: black;">&#40;</span>v<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
                token_file.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #dc143c;">token</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
                <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> write_access_token_file<span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">access</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'./'</span>, <span style="color: #dc143c;">os</span>.<span style="color: black;">W_OK</span><span style="color: black;">&#41;</span>:
                token_file = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>ACCESS_TOKEN_FILE, <span style="color: #483d8b;">'w'</span><span style="color: black;">&#41;</span>
                token_file.<span style="color: black;">write</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>
                token_file.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Token file successfully updated&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
                <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Cannot write to file, please confirm you have write permission&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> douban<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
                <span style="color: #008000;">self</span>.<span style="color: black;">key</span> = API_KEY
                <span style="color: #008000;">self</span>.<span style="color: black;">secret</span> = SECRET
                <span style="color: #008000;">self</span>.<span style="color: black;">stored_token</span> = read_access_token_file<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">def</span> update_stored_token<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, data<span style="color: black;">&#41;</span>:
                data = <span style="color: #dc143c;">cgi</span>.<span style="color: black;">parse_qs</span><span style="color: black;">&#40;</span>data, keep_blank_values=<span style="color: #008000;">False</span><span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">for</span> k, v <span style="color: #ff7700;font-weight:bold;">in</span> data.<span style="color: black;">iteritems</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
                        <span style="color: #008000;">self</span>.<span style="color: black;">stored_token</span><span style="color: black;">&#91;</span>k<span style="color: black;">&#93;</span> = <span style="color: #dc143c;">urllib</span>.<span style="color: black;">unquote</span><span style="color: black;">&#40;</span>v<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">def</span> get_request_token<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
                conn = create_connection<span style="color: black;">&#40;</span>OAUTH_SERVER<span style="color: black;">&#41;</span>
                params = <span style="color: black;">&#123;</span>
                                <span style="color: #483d8b;">'oauth_consumer_key'</span>: <span style="color: #008000;">self</span>.<span style="color: black;">key</span>,
                                <span style="color: #483d8b;">'oauth_signature_method'</span>: SIG_METHOD,
                                <span style="color: #483d8b;">'oauth_timestamp'</span>: generate_timestamp<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>,
                                <span style="color: #483d8b;">'oauth_nonce'</span>: generate_nonce<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                <span style="color: black;">&#125;</span>
                header = generate_header<span style="color: black;">&#40;</span><span style="color: #483d8b;">'GET'</span>, OAUTH_SERVER + REQUEST_TOKEN_URI, params, <span style="color: #008000;">self</span>.<span style="color: black;">secret</span>, <span style="color: #008000;">None</span><span style="color: black;">&#41;</span>
                conn.<span style="color: black;">request</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;GET&quot;</span>, REQUEST_TOKEN_URI, headers=header<span style="color: black;">&#41;</span>
                response = conn.<span style="color: black;">getresponse</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                data = response.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">if</span> response.<span style="color: black;">status</span> == <span style="color: #ff4500;">200</span>:
                        <span style="color: #008000;">self</span>.<span style="color: black;">update_stored_token</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>
                        <span style="color: #008000;">self</span>.<span style="color: black;">authorize_token</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">else</span>:
                        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;%s %s<span style="color: #000099; font-weight: bold;">\n</span>%s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>response.<span style="color: black;">status</span>, response.<span style="color: black;">reason</span>, response.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
                conn.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">def</span> authorize_token<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
                <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Open the link below to authorize the request token:&quot;</span>
                <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;http://%s%s?oauth_token=%s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>OAUTH_SERVER, AUTHORIZATION_URI, escape<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">stored_token</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'oauth_token'</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
                <span style="color: #008000;">raw_input</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Press enter to continue&quot;</span><span style="color: black;">&#41;</span>
                <span style="color: #008000;">self</span>.<span style="color: black;">get_access_token</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">def</span> get_access_token<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
                conn = create_connection<span style="color: black;">&#40;</span>OAUTH_SERVER<span style="color: black;">&#41;</span>
                params = <span style="color: black;">&#123;</span>
                                <span style="color: #483d8b;">'oauth_consumer_key'</span>: <span style="color: #008000;">self</span>.<span style="color: black;">key</span>,
                                <span style="color: #483d8b;">'oauth_token'</span>: <span style="color: #008000;">self</span>.<span style="color: black;">stored_token</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'oauth_token'</span><span style="color: black;">&#93;</span>,
                                <span style="color: #483d8b;">'oauth_sgnature_method'</span>: SIG_METHOD,
                                <span style="color: #483d8b;">'oauth_timestamp'</span>: generate_timestamp<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>,
                                <span style="color: #483d8b;">'oauth_nonce'</span>: generate_nonce<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                <span style="color: black;">&#125;</span>
                header = generate_header<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;GET&quot;</span>, OAUTH_SERVER + ACCESS_TOKEN_URI, params, <span style="color: #008000;">self</span>.<span style="color: black;">secret</span>, <span style="color: #008000;">self</span>.<span style="color: black;">stored_token</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'oauth_token_secret'</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
                conn.<span style="color: black;">request</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;GET&quot;</span>, ACCESS_TOKEN_URI, headers=header<span style="color: black;">&#41;</span>
                response = conn.<span style="color: black;">getresponse</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">if</span> response.<span style="color: black;">status</span> == <span style="color: #ff4500;">200</span>:
                        data = response.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                        write_access_token_file<span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">else</span>:
                        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;%s %s<span style="color: #000099; font-weight: bold;">\n</span>%s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>response.<span style="color: black;">status</span>, response.<span style="color: black;">reason</span>, response.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">def</span> first_run<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
                <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #483d8b;">'douban_user_id'</span> <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">self</span>.<span style="color: black;">stored_token</span>:
                        confirm = <span style="color: #008000;">raw_input</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'token file exists arleady, overwrite? ([y]/n):'</span><span style="color: black;">&#41;</span>
                        <span style="color: #ff7700;font-weight:bold;">if</span> confirm.<span style="color: black;">upper</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">'N'</span>:
                                <span style="color: #dc143c;">sys</span>.<span style="color: black;">exit</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
                <span style="color: #008000;">self</span>.<span style="color: black;">get_request_token</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">def</span> add_saying<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, content<span style="color: black;">&#41;</span>:
                <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #483d8b;">'douban_user_id'</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">self</span>.<span style="color: black;">stored_token</span>:
                        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Access token file does not exist'</span>
                        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">None</span>
                entry = <span style="color: #483d8b;">'&lt;?xml version=<span style="color: #000099; font-weight: bold;">\'</span>1.0<span style="color: #000099; font-weight: bold;">\'</span> encoding=<span style="color: #000099; font-weight: bold;">\'</span>UTF-8<span style="color: #000099; font-weight: bold;">\'</span>?&gt;'</span>\
                        + <span style="color: #483d8b;">'&lt;entry xmlns:ns0=&quot;http://www.w3.org/2005/Atom&quot; xmlns:db=&quot;http://www.douban.com/xmlns/&quot;&gt;'</span>\
                        + <span style="color: #483d8b;">'&lt;content&gt;'</span> + content + <span style="color: #483d8b;">'&lt;/content&gt;'</span>\
                        + <span style="color: #483d8b;">'&lt;/entry&gt;'</span>
                conn = create_connection<span style="color: black;">&#40;</span>SERVER<span style="color: black;">&#41;</span>
                params = <span style="color: black;">&#123;</span>
                                <span style="color: #483d8b;">'oauth_consumer_key'</span>: <span style="color: #008000;">self</span>.<span style="color: black;">key</span>,
                                <span style="color: #483d8b;">'oauth_token'</span>: <span style="color: #008000;">self</span>.<span style="color: black;">stored_token</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'oauth_token'</span><span style="color: black;">&#93;</span>,
                                <span style="color: #483d8b;">'oauth_signature_method'</span>: SIG_METHOD,
                                <span style="color: #483d8b;">'oauth_timestamp'</span>: generate_timestamp<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>,
                                <span style="color: #483d8b;">'oauth_nonce'</span>: generate_nonce<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                <span style="color: black;">&#125;</span>
                header = generate_header<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;POST&quot;</span>, SERVER + SAYING_URI, params, <span style="color: #008000;">self</span>.<span style="color: black;">secret</span>, <span style="color: #008000;">self</span>.<span style="color: black;">stored_token</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'oauth_token_secret'</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
                header<span style="color: black;">&#91;</span><span style="color: #483d8b;">'Content-Type'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'application/atom+xml'</span>
                conn.<span style="color: black;">request</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;POST&quot;</span>, SAYING_URI, entry, header<span style="color: black;">&#41;</span>
                response = conn.<span style="color: black;">getresponse</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">if</span> response.<span style="color: black;">status</span> <span style="color: #66cc66;">!</span>= <span style="color: #ff4500;">201</span>:
                        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;%s %s<span style="color: #000099; font-weight: bold;">\n</span>%s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>response.<span style="color: black;">status</span>, response.<span style="color: black;">reason</span>, response.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://phill84.org/2010/01/posting-douban-saying-using-python-%e7%94%a8python%e7%99%bc%e9%80%81%e8%b1%86%e7%93%a3%e5%bb%a3%e6%92%ad/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Syncing twitter to digu using python / 用python同步twitter到嘀咕</title>
		<link>http://phill84.org/2009/10/syncing-twitter-to-digu-using-python-%e7%94%a8python%e5%90%8c%e6%ad%a5twitter%e5%88%b0%e5%98%80%e5%92%95/</link>
		<comments>http://phill84.org/2009/10/syncing-twitter-to-digu-using-python-%e7%94%a8python%e5%90%8c%e6%ad%a5twitter%e5%88%b0%e5%98%80%e5%92%95/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 19:04:19 +0000</pubDate>
		<dc:creator>phill84</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[digu]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[sync]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[同步]]></category>
		<category><![CDATA[嘀咕]]></category>

		<guid isPermaLink="false">http://phill84.org/2009/10/syncing-twitter-to-digu-using-python-%e7%94%a8python%e5%90%8c%e6%ad%a5twitter%e5%88%b0%e5%98%80%e5%92%95/</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<pre class="brush: python; title: ; notranslate">#!/usr/bin/env python
import base64
import simplejson as json
import os
import sys
import urllib
import urllib2

global twitter_username
global digu_username
global digu_password
twitter_username = 'username'
digu_username = 'username'
digu_password = 'password'

def post_to_digu(msg):
	url = 'http://api.minicloud.com.cn/statuses/update.json'
	data = urllib.urlencode(msg)
	req = urllib2.Request(url, data)
	req.add_header(&quot;Authorization&quot;, &quot;Basic %s&quot; % base64.encodestring('%s:%s' % (digu_username, digu_password))[:-1])
	handle = urllib2.urlopen(req)

def main():
	path = sys.path[0]
	if (sys.platform[:3] == 'win'):
		path += '\\'
	else:
		path += '/'
	id_file = path + 'last_id'
	last_id = 0
	if os.path.exists(id_file):
		f = open(id_file, 'r')
	        last_id = int(f.read())
        	f.close()
	else:
		f = open(id_file, 'w')
		f.write('0')
		f.close()
	url = 'http://twitter.com/statuses/user_timeline/' + twitter_username + '.json?last_id='
	updates = json.load(urllib.urlopen(url+str(last_id)))
	new_last_id = None
	n = 0
	for update in updates:
		text = update['text']
		id = update['id']
		if (text[0] != '@') and (id &amp;gt; last_id):
			if (new_last_id &amp;lt; id):
				new_last_id = id
			text = urllib.quote(text.encode('utf-8'))
			msg = {'content': text}
                        stack.append(msg)
        while (stack)
                post_to_digu(stack.pop())
	if (new_last_id != None):
		f = open(id_file, 'w')
		f.write(str(new_last_id))

if __name__ == &quot;__main__&quot;:
    main()</pre>
]]></content:encoded>
			<wfw:commentRss>http://phill84.org/2009/10/syncing-twitter-to-digu-using-python-%e7%94%a8python%e5%90%8c%e6%ad%a5twitter%e5%88%b0%e5%98%80%e5%92%95/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Sysinfo plugin for xchat2 on linux</title>
		<link>http://phill84.org/2009/08/sysinfo-plugin-for-xchat2-on-linux/</link>
		<comments>http://phill84.org/2009/08/sysinfo-plugin-for-xchat2-on-linux/#comments</comments>
		<pubDate>Sun, 30 Aug 2009 19:23:59 +0000</pubDate>
		<dc:creator>phill84</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[sysinfo]]></category>
		<category><![CDATA[xchat]]></category>

		<guid isPermaLink="false">http://phill84.org/2009/08/sysinfo-plugin-for-xchat2-on-linux/</guid>
		<description><![CDATA[It&#8217;s my first time writing something in perl, the code is not very efficient and for now it can only display info of cpu, memory, bandwidth and uptime.]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s my first time writing something in perl, the code is not very efficient and for now it can only display info of cpu, memory, bandwidth and uptime.</p>
<pre class="brush: perl; title: ; notranslate"># Configuration
$eth = &quot;eth0&quot;;

# Script
Xchat::register(&quot;Sysinfo&quot;, &quot;0.1&quot;, &quot;System Information Displayer&quot;);
Xchat::print(&quot;Sysinfo 0.1 Loaded.&quot;);
Xchat::hook_command(&quot;uptime&quot;, &quot;uptime&quot;);
Xchat::hook_command(&quot;os&quot;, &quot;os&quot;);
Xchat::hook_command(&quot;bw&quot;, &quot;bw&quot;);
Xchat::hook_command(&quot;cpu&quot;, &quot;cpu&quot;);
Xchat::hook_command(&quot;mem&quot;, &quot;mem&quot;);

sub uptime {
	$uptime = `cat /proc/uptime | awk '{printf \$1}'`;
	$_day = 60 * 60 * 24;
	$_hour = 60 * 60;
	$_minute = 60;
	$day = int($uptime/$_day);
	$uptime %= $_day;
	$hour = int($uptime/$_hour);
	$uptime %= $_hour;
	$minute = int($uptime/$_minute);
	$uptime %= $_minute;
	$second = int($uptime);
	$uptime = &quot;&quot;;
	if($day != 0) {
		$uptime .= $day;
		if($day == 1) {
			$uptime .= &quot; day &quot;;
		} else {
			$uptime .= &quot; days &quot;;
		}
	}
	if($hour != 0) {
		$uptime .= $hour;
		if($hour == 1) {
			$uptime .= &quot; hour &quot;;
		} else {
			$uptime .= &quot; hours &quot;;
		}
	}
	if($minute != 0) {
		$uptime .= $minute;
		if($minute == 1) {
			$uptime .= &quot; minute &quot;;
		} else {
			$uptime .= &quot; minutes &quot;;
		}
	}
	$uptime .= $second;
	if($second == 1) {
		$uptime .= &quot; second&quot;;
	} else {
		$uptime .= &quot; seconds&quot;;
	}
	Xchat::command(&quot;SAY &#92;&#48;02[UPTIME]&#92;&#48;02 $uptime&quot;);
	Xchat::EAT_ALL;
}

sub os {
	$_kernel_release = `uname -r`;
	$_operating_system = `uname -o`;
	chomp($_kernel_release);
	chomp($_operating_system);
	$os = $_operating_system . &quot; &quot; . $_kernel_release;
	Xchat::command(&quot;SAY &#92;&#48;02[OS]&#92;&#48;02 $os&quot;);
	Xchat::EAT_ALL;
}

sub bw {
	$old = `cat /proc/net/dev | grep $eth | cut -d &quot;:&quot; -f 2 | tr -s &quot; &quot;| cut -d &quot; &quot; -f 1,9`;
	sleep(1);
	$new = `cat /proc/net/dev | grep $eth | cut -d &quot;:&quot; -f 2 | tr -s &quot; &quot;| cut -d &quot; &quot; -f 1,9`;
	@ary_old = split(/\s/, $old);
	@ary_new = split(/\s/, $new);
	$down = $ary_new[0] - $ary_old[0];
	$up = $ary_new[1] - $ary_old[1];
	$bw = &quot;&quot;;
	if($down &lt; 1000) {
		$bw .= $down . &quot; B/s Down &quot;;
	} else {
		$bw .= sprintf(&quot;%.02f&quot;, $down / 1000) . &quot; KB/s Down &quot;;
	}
	if($up &lt; 1000) {
		$bw .= $up . &quot; B/s Up&quot;;
	} else {
		$bw .= sprintf(&quot;%.02f&quot;, $up / 1000) . &quot; KB/s Up&quot;;
	}
	Xchat::command(&quot;SAY &#92;&#48;02[BW]&#92;&#48;02 $bw&quot;);
	Xchat::EAT_ALL;
}

sub cpu {
	$model_name = `cat /proc/cpuinfo | grep &quot;model name&quot; | tail -1 | cut -d &quot;:&quot; -f 2 | tr -s &quot; &quot;`;
	$number_cores = `cat /proc/cpuinfo | grep &quot;model name&quot; -c`;
	$freq = `cat /proc/cpuinfo | grep &quot;cpu MHz&quot; | tail -1 | cut -d &quot;:&quot; -f 2 | tr -s &quot; &quot;`;
	$idle = `vmstat | tail -1 | awk '{printf \$15}'`;
	$load = 100 - $idle;
	chomp($model_name);
	chomp($number_cores);
	chomp($freq);
	$cpuinfo = $number_cores . &quot; CPU&quot;;
	if($number_cores &gt; 1) {
		$cpuinfo .= &quot;'s&quot;;
	}
	$cpuinfo .= &quot; -&quot; . $model_name;
	$cpuinfo .= &quot; @ &quot; . int($freq) . &quot; MHz&quot; . &quot; (&quot; . $load . &quot;% Load)&quot;;
	Xchat::command(&quot;SAY &#92;&#48;02[CPU]&#92;&#48;02 $cpuinfo&quot;);
	Xchat:EAT_ALL;
}

sub mem {
	$mem_total = `free -m | grep Mem | awk '{printf \$2}'`;
	$mem_used = `free -m | grep - | awk '{printf \$3}'`;
	$swap_total = `free -m| grep Swap | awk '{printf \$2}'`;
	$swap_used = `free -m| grep Swap | awk '{printf \$3}'`;
	$meminfo = &quot;&#92;&#48;02[MEM]&#92;&#48;02 &quot; . $mem_used . &quot;/&quot; . $mem_total . &quot; MB &#92;&#48;02[SWAP]&#92;&#48;02 &quot; . $swap_used . &quot;/&quot; . $swap_total . &quot; MB&quot;;
	Xchat::command(&quot;SAY $meminfo&quot;);
	Xchat::EAT_ALL;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://phill84.org/2009/08/sysinfo-plugin-for-xchat2-on-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Download Link Converter / 下載鏈接轉換器</title>
		<link>http://phill84.org/2009/08/download-link-converter-%e4%b8%8b%e8%bc%89%e9%8f%88%e6%8e%a5%e8%bd%89%e6%8f%9b%e5%99%a8/</link>
		<comments>http://phill84.org/2009/08/download-link-converter-%e4%b8%8b%e8%bc%89%e9%8f%88%e6%8e%a5%e8%bd%89%e6%8f%9b%e5%99%a8/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 18:44:58 +0000</pubDate>
		<dc:creator>phill84</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[flashget]]></category>
		<category><![CDATA[QQ旋風]]></category>
		<category><![CDATA[轉換]]></category>
		<category><![CDATA[迅雷]]></category>

		<guid isPermaLink="false">http://phill84.org/2009/08/download-link-converter-%e4%b8%8b%e8%bc%89%e9%8f%88%e6%8e%a5%e8%bd%89%e6%8f%9b%e5%99%a8/</guid>
		<description><![CDATA[I was extremely bored this afternoon, so here it is, the converter for converting download links among FlashGet, QQ Tornado and Xunle, and also decrypting the real link. The tool is pretty much self-explanatory (and useless) so I guess there&#8217;s &#8230; <a href="http://phill84.org/2009/08/download-link-converter-%e4%b8%8b%e8%bc%89%e9%8f%88%e6%8e%a5%e8%bd%89%e6%8f%9b%e5%99%a8/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was extremely bored this afternoon, so here it is, the converter for converting download links among FlashGet, QQ Tornado and Xunle, and also decrypting the real link. The tool is pretty much self-explanatory (and useless) so I guess there&#8217;s no need for any manuals or instructions. If you are bored too, you can check out the source below, just don&#8217;t tell me how ugly it is, coz I&#8217;m fully aware of it! <img src='http://phill84.org/wp-includes/images/smilies/icon_biggrin.gif' alt="icon biggrin Download Link Converter / 下載鏈接轉換器" class='wp-smiley colorbox-604' title="Download Link Converter / 下載鏈接轉換器" />  You can find this converter on the &#8220;Tool&#8221; page, link is at the top of the page.</p>
<p>今天下午極度無聊, 就隨便寫了個可以在 FlashGet, QQ旋風和迅雷間轉換下載鏈接的小工具, 也可以直接看到真實鏈接. 功能及其直白, 就不提供什麼說明了. 如果你跟我一樣無聊, 以下有代碼奉上. 我知道代碼寫得很醜, 所以就不要提到這點啦! <img src='http://phill84.org/wp-includes/images/smilies/icon_biggrin.gif' alt="icon biggrin Download Link Converter / 下載鏈接轉換器" class='wp-smiley colorbox-604' title="Download Link Converter / 下載鏈接轉換器" />  你可以在&#8221;Tool&#8221;頁面看到這個工具, 鏈接在頁面頂部.</p>
<p><span id="more-604"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$link</span>	<span style="color: #339933;">=</span>	<span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'link'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$to</span>	<span style="color: #339933;">=</span>	<span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'to'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$from</span>	<span style="color: #339933;">=</span>	<span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$out</span>	<span style="color: #339933;">=</span>	<span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$link</span> <span style="color: #339933;">!=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$strAry</span>	<span style="color: #339933;">=</span>	<span style="color: #990000;">split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'://'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$size</span>	<span style="color: #339933;">=</span>	<span style="color: #990000;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$strAry</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$protocol</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$strAry</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strcasecmp</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$protocol</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'flashget'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$from</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'fg'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strcasecmp</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$protocol</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'qqdl'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$from</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'qq'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>  <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strcasecmp</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$protocol</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'thunder'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$from</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'xl'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$from</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$out</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'this link is not in the correct format'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$from</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$to</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$out</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'no conversion needed you stupid fuck'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$real_link</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$decoded_link</span> <span style="color: #339933;">=</span> <span style="color: #990000;">base64_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$strAry</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$decoded_link</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$out</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'this link is not in the correct format'</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$from</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'fg'</span><span style="color: #339933;">:</span>
						<span style="color: #000088;">$real_link</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'[FLASHGET]'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #000088;">$decoded_link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'qq'</span><span style="color: #339933;">:</span>
						<span style="color: #000088;">$real_link</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$decoded_link</span><span style="color: #339933;">;</span>
						<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'xl'</span><span style="color: #339933;">:</span>
						<span style="color: #000088;">$real_link</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$decoded_link</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'fg'</span><span style="color: #339933;">:</span>
						<span style="color: #000088;">$out</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'flashget://'</span><span style="color: #339933;">.</span><span style="color: #990000;">base64_encode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'[FLASHGET]'</span><span style="color: #339933;">.</span><span style="color: #000088;">$real_link</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'[FLASHGET]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'qq'</span><span style="color: #339933;">:</span>
						<span style="color: #000088;">$out</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'qqdl://'</span><span style="color: #339933;">.</span><span style="color: #990000;">base64_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$real_link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'xl'</span><span style="color: #339933;">:</span>
						<span style="color: #000088;">$out</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'thunder://'</span><span style="color: #339933;">.</span><span style="color: #990000;">base64_encode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'AA'</span><span style="color: #339933;">.</span><span style="color: #000088;">$real_link</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'ZZ'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'no_encrypt'</span><span style="color: #339933;">:</span>
						<span style="color: #000088;">$out</span> <span style="color: #339933;">=</span> <span style="color: #990000;">iconv</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GB18030'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'UTF-8'</span><span style="color: #339933;">,</span><span style="color: #000088;">$real_link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$out</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'this link is not in the correct format'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot; &gt;
&lt;html&gt;
&lt;head&gt;
&nbsp;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=&quot;utf-8&quot;&gt;
&lt;link type=&quot;text/css&quot; href=&quot;iframe.css&quot; rel=&quot;stylesheet&quot; /&gt;
&lt;style type=&quot;text/css&quot;&gt;
textarea {
  width: 100%;
  height: 4em;
}
&lt;/style&gt;
&nbsp;
&lt;/head&gt;
&lt;body&gt;
&lt;h2&gt;Download Link Converter&lt;/h2&gt;
&lt;form action=&quot;&quot; method=&quot;post&quot;&gt;
	&lt;label for=&quot;link&quot;&gt;Paste the download link here (FlashGet, QQ Tornado, or Xunlei)&lt;/label&gt;
	&lt;textarea name=&quot;link&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$link</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/textarea&gt;
&nbsp;
	&lt;label for=&quot;to&quot;&gt;
		Select the format you want to convert to:
	&lt;/label&gt;
	&amp;nbsp;
&lt;select name=&quot;to&quot;&gt;
		&lt;option value=&quot;fg&quot;&gt;FlashGet&lt;/option&gt;
		&lt;option value=&quot;qq&quot;&gt;QQ Tornado&lt;/option&gt;
		&lt;option value=&quot;xl&quot;&gt;Xunlei&lt;/option&gt;
		&lt;option value=&quot;no_encrypt&quot;&gt;Unencrypted&lt;/option&gt;
	&lt;/select&gt;
&nbsp;
	&amp;nbsp;&amp;nbsp;
	&lt;button type=&quot;submit&quot;&gt;Convert&lt;/button&gt;
&lt;/form&gt;
&nbsp;
&lt;textarea&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$out</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/textarea&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://phill84.org/2009/08/download-link-converter-%e4%b8%8b%e8%bc%89%e9%8f%88%e6%8e%a5%e8%bd%89%e6%8f%9b%e5%99%a8/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>豆瓣小組引用回復插件</title>
		<link>http://phill84.org/2009/06/%e8%b1%86%e7%93%a3%e5%b0%8f%e7%b5%84%e5%bc%95%e7%94%a8%e5%9b%9e%e5%be%a9%e6%8f%92%e4%bb%b6/</link>
		<comments>http://phill84.org/2009/06/%e8%b1%86%e7%93%a3%e5%b0%8f%e7%b5%84%e5%bc%95%e7%94%a8%e5%9b%9e%e5%be%a9%e6%8f%92%e4%bb%b6/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 13:59:13 +0000</pubDate>
		<dc:creator>phill84</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[douban]]></category>
		<category><![CDATA[greasemonkey]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[插件]]></category>
		<category><![CDATA[豆瓣]]></category>

		<guid isPermaLink="false">http://phill84.org/2009/06/%e8%b1%86%e7%93%a3%e5%b0%8f%e7%b5%84%e5%bc%95%e7%94%a8%e5%9b%9e%e5%be%a9%e6%8f%92%e4%bb%b6/</guid>
		<description><![CDATA[在顯示樓層插件的基礎上加上了引用回復功能 因為是以顯示樓層插件為基礎, 所以要求依然是 firefox+greasemonkey, 並且包括顯示樓層功能 引用回復的 link 只有在鼠標在回復區塊上時才會顯示 如果想引用留言所在頁面不是最後一頁, 因此沒有回復框, 插件會自動在頁面上加上回復框 引用完成後頁面會滾動到底部回復框 * 增加: ctrl+enter 回復功能 (04/06/2009) * 修正bug: 不能在非第一頁或最後頁創建回復框 (10/06/2009) * 增加: 如果討論分頁, 在頁首也顯示導航條 (10/06/2009) 顯示效果如下圖 請點這裡安裝]]></description>
			<content:encoded><![CDATA[<p>在顯示樓層插件的基礎上加上了引用回復功能</p>
<p>因為是以顯示樓層插件為基礎, 所以要求依然是 firefox+greasemonkey, 並且包括顯示樓層功能</p>
<p>引用回復的 link 只有在鼠標在回復區塊上時才會顯示</p>
<p>如果想引用留言所在頁面不是最後一頁, 因此沒有回復框, 插件會自動在頁面上加上回復框</p>
<p>引用完成後頁面會滾動到底部回復框</p>
<p><span style="color: #993300;">* 增加: ctrl+enter 回復功能 (04/06/2009)</span><br />
<span style="color: #993300;">* 修正bug: 不能在非第一頁或最後頁創建回復框 (10/06/2009)</span><br />
<span style="color: #993300;">* 增加: 如果討論分頁, 在頁首也顯示導航條</span><span style="color: #993300;"> (10/06/2009)</span></p>
<p><span id="more-592"></span>顯示效果如下圖</p>
<blockquote><p><a href="http://phill84.org/wp-content/uploads/2009/06/screenshot.png"><img class="alignnone size-full wp-image-591 colorbox-592" title="Screenshot" src="http://phill84.org/wp-content/uploads/2009/06/screenshot.png" alt="screenshot 豆瓣小組引用回復插件" width="641" height="446" /></a></p></blockquote>
<p>請點<a href="http://userscripts.org/scripts/show/50759">這裡</a>安裝</p>
]]></content:encoded>
			<wfw:commentRss>http://phill84.org/2009/06/%e8%b1%86%e7%93%a3%e5%b0%8f%e7%b5%84%e5%bc%95%e7%94%a8%e5%9b%9e%e5%be%a9%e6%8f%92%e4%bb%b6/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>豆瓣討論區顯示樓層數GreaseMonkey插件</title>
		<link>http://phill84.org/2009/06/%e8%b1%86%e7%93%a3%e8%a8%8e%e8%ab%96%e5%8d%80%e9%a1%af%e7%a4%ba%e6%a8%93%e5%b1%a4%e6%95%b8greasemonkey%e6%8f%92%e4%bb%b6/</link>
		<comments>http://phill84.org/2009/06/%e8%b1%86%e7%93%a3%e8%a8%8e%e8%ab%96%e5%8d%80%e9%a1%af%e7%a4%ba%e6%a8%93%e5%b1%a4%e6%95%b8greasemonkey%e6%8f%92%e4%bb%b6/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 17:42:51 +0000</pubDate>
		<dc:creator>phill84</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[douban]]></category>
		<category><![CDATA[greasemonkey]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[豆瓣]]></category>

		<guid isPermaLink="false">http://phill84.org/2009/06/%e8%b1%86%e7%93%a3%e8%a8%8e%e8%ab%96%e5%8d%80%e9%a1%af%e7%a4%ba%e6%a8%93%e5%b1%a4%e6%95%b8greasemonkey%e6%8f%92%e4%bb%b6/</guid>
		<description><![CDATA[如題 requirements 是 firefox + greasemonkey 啟用後的效果如下 * NOTE: 此插件已不再更新，且因為豆瓣更改頁面布局此插件業已失效，請點擊 這裡 查看豆瓣引用回覆插件]]></description>
			<content:encoded><![CDATA[<p>如題</p>
<p>requirements 是 firefox + greasemonkey</p>
<p>啟用後的效果如下</p>
<blockquote><p><a href="http://phill84.org/wp-content/uploads/2009/06/screenshot_1.png"><img class="alignnone size-full wp-image-588 colorbox-590" title="Screenshot" src="http://phill84.org/wp-content/uploads/2009/06/screenshot_1.png" alt="screenshot 1 豆瓣討論區顯示樓層數GreaseMonkey插件" width="298" height="449" /></a></p></blockquote>
<p><span id="more-590"></span></p>
<blockquote><p><a href="http://phill84.org/wp-content/uploads/2009/06/screenshot_2.png"><img class="alignnone size-medium wp-image-589 colorbox-590" title="Screenshot" src="http://phill84.org/wp-content/uploads/2009/06/screenshot_2-449x147.png" alt="screenshot 2 449x147 豆瓣討論區顯示樓層數GreaseMonkey插件" width="449" height="147" /></a></p></blockquote>
<p><span style="color: #ff0000;">* NOTE: 此插件已不再更新，且因為豆瓣更改頁面布局此插件業已失效，請點擊 <a href="http://phill84.org/2009/06/%E8%B1%86%E7%93%A3%E5%B0%8F%E7%B5%84%E5%BC%95%E7%94%A8%E5%9B%9E%E5%BE%A9%E6%8F%92%E4%BB%B6/">這裡</a> 查看豆瓣引用回覆插件</span></p>
]]></content:encoded>
			<wfw:commentRss>http://phill84.org/2009/06/%e8%b1%86%e7%93%a3%e8%a8%8e%e8%ab%96%e5%8d%80%e9%a1%af%e7%a4%ba%e6%a8%93%e5%b1%a4%e6%95%b8greasemonkey%e6%8f%92%e4%bb%b6/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>寫了個超級簡單的 chatroom &#8230;</title>
		<link>http://phill84.org/2009/04/%e5%af%ab%e4%ba%86%e5%80%8b%e8%b6%85%e7%b4%9a%e7%b0%a1%e5%96%ae%e7%9a%84-chatroom/</link>
		<comments>http://phill84.org/2009/04/%e5%af%ab%e4%ba%86%e5%80%8b%e8%b6%85%e7%b4%9a%e7%b0%a1%e5%96%ae%e7%9a%84-chatroom/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 11:03:48 +0000</pubDate>
		<dc:creator>phill84</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[chatroom]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://phill84.org/2009/04/%e5%af%ab%e4%ba%86%e5%80%8b%e8%b6%85%e7%b4%9a%e7%b0%a1%e5%96%ae%e7%9a%84-chatroom/</guid>
		<description><![CDATA[兩個 class 加兩個 jsp &#8230; 功能極其有限 lol source 在這裡]]></description>
			<content:encoded><![CDATA[<p>兩個 class 加兩個 jsp &#8230;<br />
功能極其有限 lol</p>
<p>source 在<a href="http://code.google.com/p/simplechatroom/source/browse/">這裡</a></p>
]]></content:encoded>
			<wfw:commentRss>http://phill84.org/2009/04/%e5%af%ab%e4%ba%86%e5%80%8b%e8%b6%85%e7%b4%9a%e7%b0%a1%e5%96%ae%e7%9a%84-chatroom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>同步 twitter 到 飯否</title>
		<link>http://phill84.org/2009/03/%e5%90%8c%e6%ad%a5-twitter-%e5%88%b0-%e9%a3%af%e5%90%a6/</link>
		<comments>http://phill84.org/2009/03/%e5%90%8c%e6%ad%a5-twitter-%e5%88%b0-%e9%a3%af%e5%90%a6/#comments</comments>
		<pubDate>Fri, 27 Mar 2009 09:16:01 +0000</pubDate>
		<dc:creator>phill84</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[fanfou]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[sync]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[同步]]></category>
		<category><![CDATA[飯否]]></category>

		<guid isPermaLink="false">http://phill84.org/2009/03/%e5%90%8c%e6%ad%a5-twitter-%e5%88%b0-%e9%a3%af%e5%90%a6/</guid>
		<description><![CDATA[google 看到 raptium同學的 post Twitter和饭否同步 像我這種懶人自然就拿來用了 不過又不想把 twitter 上的回復也 sync 到飯否 so 加了一個 statement 把 @blah 都過濾了 如果有比我更懶得同學也想這麼做的話只要把 elif snode.nodeName == 'text': 改成 elif &#40;snode.nodeName == 'text'&#41; and &#40;snode.childNodes&#91;0&#93;.nodeValue&#91;0&#93; != '@'&#41;: 就可以了]]></description>
			<content:encoded><![CDATA[<p>google 看到 <a href="http://www.raptium.com/">raptium</a>同學的 post <a href="http://www.raptium.com/2009/02/01/twitter-sync-with-fanfou/">Twitter和饭否同步</a></p>
<p>像我這種懶人自然就拿來用了</p>
<p>不過又不想把 twitter 上的回復也 sync 到飯否</p>
<p>so 加了一個 statement 把 @blah 都過濾了</p>
<p>如果有比我更懶得同學也想這麼做的話只要把</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">elif</span> snode.<span style="color: black;">nodeName</span> == <span style="color: #483d8b;">'text'</span>:</pre></div></div>

<p>改成</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">elif</span> <span style="color: black;">&#40;</span>snode.<span style="color: black;">nodeName</span> == <span style="color: #483d8b;">'text'</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: black;">&#40;</span>snode.<span style="color: black;">childNodes</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">nodeValue</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">'@'</span><span style="color: black;">&#41;</span>:</pre></div></div>

<p>就可以了 <img src='http://phill84.org/wp-includes/images/smilies/icon_biggrin.gif' alt="icon biggrin 同步 twitter 到 飯否" class='wp-smiley colorbox-569' title="同步 twitter 到 飯否" /> </p>
]]></content:encoded>
			<wfw:commentRss>http://phill84.org/2009/03/%e5%90%8c%e6%ad%a5-twitter-%e5%88%b0-%e9%a3%af%e5%90%a6/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to distinguish incoming trunks in asterisk-java</title>
		<link>http://phill84.org/2009/03/how-to-distinguish-incoming-trunks-in-asterisk-java/</link>
		<comments>http://phill84.org/2009/03/how-to-distinguish-incoming-trunks-in-asterisk-java/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 10:28:52 +0000</pubDate>
		<dc:creator>phill84</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[1.6]]></category>
		<category><![CDATA[accountcode]]></category>
		<category><![CDATA[asterisk]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[sip]]></category>
		<category><![CDATA[trunk]]></category>

		<guid isPermaLink="false">http://phill84.org/2009/03/how-to-distinguish-incoming-trunk-in-asterisk-java/</guid>
		<description><![CDATA[Suppose you have asterisk 1.6 with freepbx and you are developing with the latest asterisk-java library. Somehow you wanna perform different tasks based on calls coming through different SIP trunks. When there&#8217;s a new incoming call, asterisk-java will trigger a &#8230; <a href="http://phill84.org/2009/03/how-to-distinguish-incoming-trunks-in-asterisk-java/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Suppose you have asterisk 1.6 with freepbx and you are developing with the latest asterisk-java library. Somehow you wanna perform different tasks based on calls coming through different SIP trunks.</p>
<p>When there&#8217;s a new incoming call, asterisk-java will trigger a newChannelEvent, but there&#8217;s no information in this event that can be used for distinguish from which trunk this call is coming in.</p>
<p>By default the accountcode in this NewChannelEvent is null, which makes sense because the accountcode is used for billing, and no one, at least not many people, wants to record the charge of SIP trunk because that&#8217;s usually done by the SIP provider to which the trunk is registered to. But since the accountcode is null and useless here, maybe we can use it as an identifier to distinguish the incoming trunk, it may be not the smartest solution, but at least it&#8217;s a working one <img src='http://phill84.org/wp-includes/images/smilies/icon_biggrin.gif' alt="icon biggrin How to distinguish incoming trunks in asterisk java" class='wp-smiley colorbox-563' title="How to distinguish incoming trunks in asterisk java" /> <span id="more-563"></span></p>
<p>The solution is pretty easy. Just open extensions_custom.conf and add<br />
<code>[ext-did-custom]<br />
exten =&gt; &lt;username from your sip provider&gt;,1,Set(CDR(accountcode)=&lt;some account&gt;)</code><br />
et voilà! <img src='http://phill84.org/wp-includes/images/smilies/icon_wink.gif' alt="icon wink How to distinguish incoming trunks in asterisk java" class='wp-smiley colorbox-563' title="How to distinguish incoming trunks in asterisk java" /> </p>
<p>If you try to make a call from outside now, in this NewChannelEvent the accountcode is still null, but there will be a NewAccountCodeEvent and you can see that the accountcode is set in this event, and from the same uniqueid you can tell that both the NewChannelEvent and NewAccountCodeEvent belong to the same call.</p>
<p>*note: Remeber that you should never manually edit extensions_additional.conf, the file is generated by freepbx and all the changes you have done will be overrided the next time you apply some changes in freepbx</p>
]]></content:encoded>
			<wfw:commentRss>http://phill84.org/2009/03/how-to-distinguish-incoming-trunks-in-asterisk-java/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

