<?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; 同步</title>
	<atom:link href="http://phill84.org/tag/%e5%90%8c%e6%ad%a5/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>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>同步 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>
	</channel>
</rss>

