-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
executable file
·51 lines (43 loc) · 1.41 KB
/
test.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import json
from StringIO import StringIO
from authorization.clientlogin import ClientLogin
from sql.sqlbuilder import SQL
import ftclient
from fileimport.fileimporter import CSVImporter
from django.conf import settings
from translate import translate
# make sure we can do local imports
thisDir = os.path.dirname(__file__)
sys.path = [thisDir] + sys.path
token = ClientLogin().authorize(settings.USERNAME, settings.PASSWORD)
ft_client = ftclient.ClientLoginFTClient(token)
tableid = 575705
newTableConfig = {
'tablename': {
'address_japanese':'LOCATION',
'address_english':'STRING'
}
}
#newTableId = ft_client.query(SQL().createTable(newTableConfig)).split("\n")[1]
newTableId = 1614172
print 'newTableId:', newTableId
resultText = ft_client.query('SELECT * FROM %s LIMIT 1' % tableid)
print 'sql result:', resultText
resultUnicode = unicode(resultText, encoding='utf-8')
rows = StringIO(resultUnicode)
rows.readline() # discard header
for row in rows:
row = row[:-1]
fields = row.split(',')
print fields
jploc = fields[0]
enloc = translate(jploc, u'ja')
print 'enloc:', enloc
ftResponse = ft_client.query(u"INSERT INTO %s ('address_japanese', 'address_english') VALUES ('%s', '%s')"
% (newTableId, jploc, enloc))
rowid = int(ftResponse.split("\n")[1])
print 'Inserted %d' % rowid