Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Korakot Chaovavanich http://korakot.stumbleupon.com

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Thai election ID checking

The online service here aims to help people
check where they are to vote. However, it can be
used as ID certification as well.
   1  
   2  # nnnn is the id to be checked
   3  http://www.dopa.go.th/cgi-bin/inqelect.sh?pid=nnnn

Here I make it into a function call.
   1  
   2  import urllib, re
   3  def getname(id):
   4    url = 'http://www.dopa.go.th/cgi-bin/inqelect.sh?pid=' + str(id)
   5    src = urllib.urlopen(url).read()
   6    pat = '<H3> *(.*?) *<'
   7    name = re.findall(pat, src)[0]  # don't use other info
   8    return name
   9  
  10  print getname(5100900050063)  # show a name (one of my relatives)

Get LAST_INSERT_ID from Symbian DBMS

   1  
   2  # table schema
   3  # CREATE TABLE person (id COUNTER, name VARCHAR)
   4  
   5  db = e32db.Dbms()
   6  db.begin()  # begin transaction (lock other inserts)
   7  db.execute(u"INSERT INTO person(name) VALUES 'korakot' ") # insert a new row
   8  
   9  dbv = e32db.Db_view()
  10  dbv.prepare(db, u"SELECT id FROM person ORDER BY id DESC")
  11  dbv.first_line()
  12  dbv.get_line()
  13  last_id = dbv.col(1)  # get it!
  14  
  15  db.commit()  # commit the transaction
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS