| Line 58... |
Line 58... |
| 58 |
|
58 |
|
| 59 |
REPLACE_QUERY="""
|
59 |
REPLACE_QUERY="""
|
| 60 |
REPLACE INTO newuserlinkssegmentation( user_id, brand, source,category_id, count, weight,modified)
|
60 |
REPLACE INTO newuserlinkssegmentation( user_id, brand, source,category_id, count, weight,modified)
|
| 61 |
SELECT user_id, brand, source,category_id, count, weight,created
|
61 |
SELECT user_id, brand, source,category_id, count, weight,created
|
| 62 |
FROM newuserlinkssegmentation7days
|
62 |
FROM newuserlinkssegmentation7days
|
| 63 |
WHERE user_id =%s and brand='%s' and category_id=%s and source=%s
|
63 |
WHERE user_id =%s and brand=%s and category_id=%s and source=%s
|
| 64 |
"""
|
64 |
"""
|
| 65 |
|
65 |
|
| 66 |
|
66 |
|
| 67 |
userMap = {} #key - user_id val - brand map
|
67 |
userMap = {} #key - user_id val - brand map
|
| 68 |
userMobileCategory={}
|
68 |
userMobileCategory={}
|
| Line 336... |
Line 336... |
| 336 |
checkUserForUpdate(r[0],r[1],r[2])
|
336 |
checkUserForUpdate(r[0],r[1],r[2])
|
| 337 |
conn.close()
|
337 |
conn.close()
|
| 338 |
def checkUserForUpdate(userId,brand,category):
|
338 |
def checkUserForUpdate(userId,brand,category):
|
| 339 |
print '********** Checking users brand present or not in the master table *********'
|
339 |
print '********** Checking users brand present or not in the master table *********'
|
| 340 |
sources = ['product_view','clicks','filters','orders','preferences']
|
340 |
sources = ['product_view','clicks','filters','orders','preferences']
|
| 341 |
datesql= "select distinct brand from newuserlinkssegmentation where user_id=%s and brand='%s' and category_id=%s"
|
341 |
datesql= "select distinct brand from newuserlinkssegmentation where user_id=%s and brand=%s and category_id=%s"
|
| 342 |
conn = getDbConnection()
|
342 |
conn = getDbConnection()
|
| 343 |
cursor = conn.cursor()
|
343 |
cursor = conn.cursor()
|
| 344 |
cursor.execute(datesql,(userId,brand,category))
|
344 |
cursor.execute(datesql,(userId,brand,category))
|
| 345 |
result = cursor.fetchone()
|
345 |
result = cursor.fetchone()
|
| 346 |
print 'Result in Check user for update',result
|
346 |
print 'Result in Check user for update',result
|
| 347 |
if len(result)==0:
|
347 |
if len(result)==0:
|
| 348 |
insertNewUserLinkDetails(userId,brand,category)
|
348 |
insertNewUserLinkDetails(userId,brand,category)
|
| 349 |
else:
|
349 |
else:
|
| 350 |
datesql= "select distinct source from newuserlinkssegmentation where user_id=%s and brand='%s' and category_id=%s"
|
350 |
datesql= "select distinct source from newuserlinkssegmentation where user_id=%s and brand=%s and category_id=%s"
|
| 351 |
cursor.execute(datesql,(userId,result[0][0],category))
|
351 |
cursor.execute(datesql,(userId,result[0][0],category))
|
| 352 |
result = cursor.fetchall()
|
352 |
result = cursor.fetchall()
|
| 353 |
for source in result:
|
353 |
for source in result:
|
| 354 |
userReplaceData(userId,brand,category, source)
|
354 |
userReplaceData(userId,brand,category, source)
|
| 355 |
sources.remove(source)
|
355 |
sources.remove(source)
|
| Line 367... |
Line 367... |
| 367 |
conn.close()
|
367 |
conn.close()
|
| 368 |
|
368 |
|
| 369 |
def insertNewUserLinkDetails(userId,brand,category):
|
369 |
def insertNewUserLinkDetails(userId,brand,category):
|
| 370 |
print 'Data needs to be inserted as the brand was not present earlier', userId,brand,category
|
370 |
print 'Data needs to be inserted as the brand was not present earlier', userId,brand,category
|
| 371 |
conn = getDbConnection()
|
371 |
conn = getDbConnection()
|
| 372 |
selectNewUser="select * from newuserlinkssegmentation7days where user_id=%s and brand='%s' and category_id=%s"
|
372 |
selectNewUser="select * from newuserlinkssegmentation7days where user_id=%s and brand=%s and category_id=%s"
|
| 373 |
cursor = conn.cursor()
|
373 |
cursor = conn.cursor()
|
| 374 |
cursor.execute(selectNewUser,(userId,brand,category))
|
374 |
cursor.execute(selectNewUser,(userId,brand,category))
|
| 375 |
result = cursor.fetchall()
|
375 |
result = cursor.fetchall()
|
| 376 |
print 'Result while inserting new record in master',result
|
376 |
print 'Result while inserting new record in master',result
|
| 377 |
for r in result:
|
377 |
for r in result:
|
| Line 381... |
Line 381... |
| 381 |
conn.close()
|
381 |
conn.close()
|
| 382 |
|
382 |
|
| 383 |
def insertNewUserLinkDetailsSourceWise(userId,brand,category,source):
|
383 |
def insertNewUserLinkDetailsSourceWise(userId,brand,category,source):
|
| 384 |
print 'Data needs to be inserted as the source was not present earlier', userId,brand,category,source
|
384 |
print 'Data needs to be inserted as the source was not present earlier', userId,brand,category,source
|
| 385 |
conn = getDbConnection()
|
385 |
conn = getDbConnection()
|
| 386 |
selectNewUser="select * from newuserlinkssegmentation7days where user_id=%s and brand='%s' and category_id=%s and source='%s'"
|
386 |
selectNewUser="select * from newuserlinkssegmentation7days where user_id=%s and brand=%s and category_id=%s and source=%s"
|
| 387 |
cursor = conn.cursor()
|
387 |
cursor = conn.cursor()
|
| 388 |
cursor.execute(selectNewUser,(userId,brand,category,source))
|
388 |
cursor.execute(selectNewUser,(userId,brand,category,source))
|
| 389 |
result = cursor.fetchall()
|
389 |
result = cursor.fetchall()
|
| 390 |
print 'Result while inserting new record in master',result
|
390 |
print 'Result while inserting new record in master',result
|
| 391 |
for r in result:
|
391 |
for r in result:
|