Exemplo n.º 1
0
# coding:utf-8

import sys
from squawk.query import *
from squawk.parsers.csvparser import *
import re

if len(sys.argv) == 2:
    name = sys.argv[1]
else:
    name = ''

query = Query("SELECT Name,Phone FROM file WHERE Name LIKE '%%%s%%'" % name)
source = CSVParser("addressbook.csv")

for row in query(source):
        #print row
	print '%s => %s' % (row['name'], row['phone'])
Exemplo n.º 2
0
f = open('parking_key_list.py', 'w')
f.write('parking = {\n')

tree = etree.parse(open(parking_datastore_file, 'rb'))
root = tree.getroot()

for i in range(1, 181):
    if len(str(i)) == 1 :
        i='00'+str(i)
    if len(str(i)) == 2 :
        i='0'+str(i)

    source = CSVParser(tpis_parking_file)
    query = Query("SELECT name FROM file WHERE id='%s'" % i)
    name = [ row['name'] for row in query(source) ]

    if name:
        name = name[0]
        for child in root:
            #for son in child.iter():
            for son in child:
                if son.tag == 'name':
                    if son.text == name.decode('utf-8') :
                        e = (son.getparent())
                        f.write('\'%s\' : \'%s\',\n' % (i, e[0].text))
                        print '%s %s => %s' % (i, name, e[0].text)

                                               
f.write('}')
f.close()