Skip to content

Instantly share code, notes, and snippets.

@JerryFleming
Last active December 17, 2015 01:49
Show Gist options
  • Save JerryFleming/5530681 to your computer and use it in GitHub Desktop.
Save JerryFleming/5530681 to your computer and use it in GitHub Desktop.
Format your phone book in Chinese locale.
#!/usr/bin/python3
# Format your phone book in Chinese locale.
# This requires SL4A <https://code.google.com/p/android-scripting/>
# and Python3 <https://code.google.com/p/python-for-android/wiki/Python3>.
# by Jerry Fleming <jerryfleming2006@gmail.com> on 2013-03-25.
# No rights reserved. Use at your own risk.
import sqlite3
import re
path = '/dbdata/databases/com.android.providers.'
con = sqlite3.connect(path + 'contacts/contacts2.db')
cur = con.cursor()
cur.execute('''SELECT _id, number, name FROM view_v1_phones WHERE account_name='vnd.sec.contact.phone' ORDER BY name''')
cleanp = re.compile('[ +()-]')
nump = re.compile('^(86)?(.*)(.{4})(.{4})$')
def format(x):
ret = '%s-%s-%s' % (x.group(2), x.group(3), x.group(4))
if ret.startswith('-'): ret = ret[1:]
return ret
for row in cur:
num = cleanp.sub('', row[1])
num = nump.sub(format, num)
cur.execute('''UPDATE data SET data1='%s' WHERE _id=%s; -- %s''' % (num, row[0], row[2])
@JerryFleming
Copy link
Author

How can I set the filetype to be python?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment