File: updateShortcode.py

package info (click to toggle)
ibus-array 0.2.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,432 kB
  • sloc: ansic: 1,060; python: 279; sed: 6; makefile: 5; sh: 1
file content (32 lines) | stat: -rwxr-xr-x 814 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sqlite3 as sqlite

def array_updatedb(table_file, table):
	con = sqlite.connect("array.db")
	cur = con.cursor()
	cur.execute('select * from ' + table)
	tbl = cur.fetchall()

	# read from the text table
	f = open(table_file, 'r')
	z = map(lambda x:x.split('\t'), filter(lambda k:(k[0] != '#' and k[0] != '%' and len(k.strip()) != 0), f.readlines()))
	k = map(lambda y:(y[0].lower(), y[1].strip(' \n')), z)
	f.close()

	# update the database
	for i, j in k:
		cur.execute('INSERT INTO ' + table + ' (keys, ch) VALUES ("' + i + '", "' + j + '");')

	con.commit()
	con.close()

# empty tables
con = sqlite.connect("array.db")
cur = con.cursor()
cur.execute('DELETE FROM simple;')
con.commit()
con.close()

array_updatedb('array-shortcode-20210725.cin', 'simple')