/
Languages.py
92 lines (65 loc) · 2.66 KB
/
Languages.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import sqlite3
import ConfReader
import FileMgr
def insertOrUpdateRecord(jsondata,tblName):
db = sqlite3.connect('/home/pi/khooloo.sqlite')
c = db.cursor()
for i in range(len(jsondata)):
Id = jsondata[i]['Id']
query ="delete from "+tblName+" where Id='"+str(Id)+"'"
c.execute(query)
if "BoxID" in jsondata[i].keys() and "ReferenceID" in jsondata[i].keys():
query ="delete from "+tblName+" where BoxID='"+str(jsondata[i]['BoxID'])+"'" + " and ReferenceID='"+str(jsondata[i]['ReferenceID'])+"'"
print('Record deleted for '+tblName+' :'+str(Id))
c.execute(query)
query ='insert into '+tblName+'('
cols = ''
vals = ''
try:
for key in jsondata[i].keys():
try:
key = key.encode('UTF-8')
except Exception,e:
key = key
value =jsondata[i][key]
try:
value = value.encode('UTF-8')
except Exception,e:
value = value
try:
value = value.replace('"','')
except Exception,e:
value = value
#Check if it is a file to download and download it.
if "IsActive" in jsondata[i].keys():
if jsondata[i]["IsActive"]==1:
FileMgr.CheckAndDownloadFile(key,value)
else:
FileMgr.CheckAndDownloadFile(key,value)
if 'Id' in key:
print('Record Added/Updated for '+tblName+' :'+str(value))
if 'AlbumDetails' in key:
insertOrUpdateRecord(value,'AlbumDetails')
else:
if 'BoxMappings' in key:
insertOrUpdateRecord(value,"ArticleBoxMapping")
else:
if value is not None:
cols = cols + key + ','
vals = vals +'"'+ str(value)+ '",'
query += cols[:-1] +') values('+vals[:-1]+');'
c.execute(query)
#print(query)
except Exception,e:
print 'Insert Error for ['+ tblName +'] id=' + str(Id) +' details:'+ str(e)
continue
db.commit()
# lastSyncDateTime= "0001-01-01%2000:00:00.000" #datetime.datetime.now()
#
# apiurl = "http://168.63.241.212/API/GetLanguages/"+str(lastSyncDateTime)
# j = urllib2.urlopen(apiurl)
# js = json.load(j)
# imgpath = js['ReturnObject']
# results = len(imgpath)
#imgpath = GetCMSData.GetData('Adverts')
#insertOrUpdateRecord(imgpath,"Language")