Posts Tagged ‘Programming’

Python unescape javascript escapped UTF8 sequence

Sunday, March 16th, 2008

尋找這種答案很浪費生命,記錄下來

print "".join([(len(i)>0 and unichr(int(i,16)) or "") for i in url.split('%u')])

MySQL UTF8 Import

Saturday, March 15th, 2008
mysql -u root --default_character_set utf8 -p database < import.sql

沒有亂碼了 [aha

簡體 UTF8 -> 繁體/正體 UTF8

Saturday, March 15th, 2008

Encode-CNmap 是好朋友
雖然字表沒有完整,但是大部份都有轉換成功,而且使用上也不錯簡單
轉換文字檔案:
cnmap -u2cb5 utf8.txt > utf8-cntrad.txt

對於懶得在 Python 下面 implement 繁簡轉換的人(me?)實在很好用:

import commands
s = commands.getoutput("echo '简体中文' | cnmap -ucb5")
print s

說真的,這方法最好別用 XD

Python-pycurl Note

Saturday, March 15th, 2008
import pycurl
c = pycurl.Curl()
c.setopt(pycurl.URL, "http://blog.tarotoast.com/")
import StringIO
b = StringIO.StringIO()
c.setopt(pycurl.WRITEFUNCTION, b.write)
c.setopt(pycurl.USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506; InfoPath.2)")
c.setopt(pycurl.REFERER, "http://blog.tarotoast.com/")
c.perform()
print b.getvalue()
All Rights Reserved Copyright © 2008 Design by StyleShout and Clazh