<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: thai code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Tue, 07 Oct 2008 14:44:30 GMT</pubDate>
    <description>DZone Snippets: thai code</description>
    <item>
      <title>Thai election ID checking</title>
      <link>http://snippets.dzone.com/posts/show/1716</link>
      <description>The online service &lt;a href=http://www.dopa.go.th/online/inqelect.htm&gt;here&lt;/a&gt; aims to help people&lt;br /&gt;check where they are to vote. However, it can be&lt;br /&gt;used as ID certification as well.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# nnnn is the id to be checked&lt;br /&gt;http://www.dopa.go.th/cgi-bin/inqelect.sh?pid=nnnn&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Here I make it into a function call.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import urllib, re&lt;br /&gt;def getname(id):&lt;br /&gt;  url = 'http://www.dopa.go.th/cgi-bin/inqelect.sh?pid=' + str(id)&lt;br /&gt;  src = urllib.urlopen(url).read()&lt;br /&gt;  pat = '&lt;H3&gt; *(.*?) *&lt;'&lt;br /&gt;  name = re.findall(pat, src)[0]  # don't use other info&lt;br /&gt;  return name&lt;br /&gt;&lt;br /&gt;print getname(5100900050063)  # show a name (one of my relatives)&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 19 Mar 2006 16:30:32 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1716</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
    <item>
      <title>Inputing non-ascii characters</title>
      <link>http://snippets.dzone.com/posts/show/631</link>
      <description>My mobile phone (6600) doesn't have a Thai input method.&lt;br /&gt;(You can buy a special software to do it)&lt;br /&gt;After a lot of my thought experiments, I got an easy&lt;br /&gt;example from my friend on this. You do a 2-level popup menu&lt;br /&gt;to let people choose from the character table.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;from appuifw import *&lt;br /&gt;&lt;br /&gt;def thai_input():&lt;br /&gt;    first_list = ['  '.join(thai_char[i:i+11]) for i in range(0,77,11)]&lt;br /&gt;    y = popup_menu(first_list, u'select Thai char')&lt;br /&gt;    if y is not None:&lt;br /&gt;        x = popup_menu(thai_char[11*y:11*(y+1)], u'select Thai char')&lt;br /&gt;        if x is not None:&lt;br /&gt;            t.add(thai_char[11*y + x])&lt;br /&gt;&lt;br /&gt;thai_char = [unichr(0x0e01+i) for i in range(77)]   # 77 thai characters&lt;br /&gt;&lt;br /&gt;app.body = t = Text()&lt;br /&gt;app.menu = [(u'thai', thai_input), (u'clear screen', t.clear)] &lt;br /&gt;&lt;br /&gt;# wait for user to exit program&lt;br /&gt;import e32      &lt;br /&gt;lock = e32.Ao_lock() &lt;br /&gt;app.exit_key_handler=lock.signal&lt;br /&gt;lock.wait()&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;For other language, you can change the unicode offset (0x0e01)&lt;br /&gt;and number of characters (77) to that of your language.&lt;br /&gt;One requirement for this method is that the phone must be&lt;br /&gt;able to display font in your language already. &lt;br /&gt;(I have previously install Thai font on my 6600)&lt;br /&gt;An alternative method to implement this will be manually drawing&lt;br /&gt;your text (combile character from image font file).&lt;br /&gt;I may do that some day.</description>
      <pubDate>Sun, 04 Sep 2005 21:48:52 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/631</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
    <item>
      <title>Using utf-8 in python</title>
      <link>http://snippets.dzone.com/posts/show/126</link>
      <description>Convert a byte string into a Unicode string and back again.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;s = "hello normal string"&lt;br /&gt;u = unicode(s, "utf-8")&lt;br /&gt;backToBytes = u.encode("utf-8")&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;For Thai, python uses cp874 encoding.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;s = ''    # my thai name&lt;br /&gt;t = s.decode('cp874')  # same as unicode(..)&lt;br /&gt;appuifw.note(t, 'info')&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 11 Apr 2005 04:10:26 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/126</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
    <item>
      <title>Change Gmail encoding to display thai.</title>
      <link>http://snippets.dzone.com/posts/show/124</link>
      <description>Some emails send from yahoo and hotmail will display thai incorrectly. This bookmarklet re-encode it by shifting the unicode numbers. Can be applied to some language whose encoding is in the same "shifting" order.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;javascript:(function(){  map=[];for(i=161;i&lt;251;i++)map[i]=String.fromCharCode(i+3424);  function thai(s){s2='';for(var i=0;i&lt;s.length;i++){n=s.charCodeAt(i);if(n&gt;160&amp;&amp;n&lt;251) s2+=map[n];else s2+=s.charAt(i)}return s2}   function rc_thai(el){if(el.nodeType== 3){el.data=thai(el.data);return} if(el.tagName == 'SCRIPT') return; for (var i=0; i&lt;el.childNodes.length; i++) rc_thai(el.childNodes[i])}   for(i=0;i&lt;4;i++){if(fi=window.frames[0].frames[i].document.getElementById('fi')) break}  rc_thai(fi); })();&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;The one-liner version above maybe difficult to read.&lt;br /&gt;Here's a reorganized one&lt;br /&gt;&lt;code&gt;&lt;br /&gt;javascript:(function(){&lt;br /&gt;map=[];&lt;br /&gt;/* create conversion table */&lt;br /&gt;for(i=161;i&lt;251;i++) {&lt;br /&gt;  map[i]=String.fromCharCode(i+3424);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function thai(s){&lt;br /&gt;  s2='';&lt;br /&gt;  for(var i=0;i&lt;s.length;i++){&lt;br /&gt;    n=s.charCodeAt(i);&lt;br /&gt;    if(n&gt;160&amp;&amp;n&lt;251) &lt;br /&gt;      s2+=map[n];&lt;br /&gt;    else &lt;br /&gt;      s2+=s.charAt(i)&lt;br /&gt;  }&lt;br /&gt;  return s2&lt;br /&gt;}   &lt;br /&gt;&lt;br /&gt;/* recursively convert encoding of sub-element */&lt;br /&gt;function rc_thai(el){&lt;br /&gt;  if(el.nodeType== 3){&lt;br /&gt;    el.data=thai(el.data);&lt;br /&gt;    return&lt;br /&gt;  } &lt;br /&gt;  if(el.tagName == 'SCRIPT') &lt;br /&gt;    return; &lt;br /&gt;  for (var i=0; i&lt;el.childNodes.length; i++)&lt;br /&gt;    rc_thai(el.childNodes[i])&lt;br /&gt;}   &lt;br /&gt;&lt;br /&gt;/* finding the content element in sub-sub-frame */&lt;br /&gt;for(i=0;i&lt;4;i++){&lt;br /&gt;  if(fi=window.frames[0].frames[i].document.getElementById('fi'))&lt;br /&gt;    break&lt;br /&gt;}  &lt;br /&gt;&lt;br /&gt;/* change that element (and all its descendants */&lt;br /&gt;rc_thai(fi); &lt;br /&gt;})();&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 11 Apr 2005 03:57:06 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/124</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
