| 16136 |
kshitij.so |
1 |
from xlrd import open_workbook
|
|
|
2 |
from datetime import date, datetime, timedelta
|
|
|
3 |
from email import encoders
|
|
|
4 |
from email.mime.base import MIMEBase
|
|
|
5 |
from email.mime.multipart import MIMEMultipart
|
|
|
6 |
from email.mime.text import MIMEText
|
|
|
7 |
from xlrd import open_workbook
|
|
|
8 |
from xlutils.copy import copy
|
|
|
9 |
from xlwt.Workbook import Workbook
|
|
|
10 |
import MySQLdb
|
|
|
11 |
import smtplib
|
|
|
12 |
import time
|
|
|
13 |
import xlwt
|
|
|
14 |
import pymongo
|
|
|
15 |
from datetime import datetime
|
|
|
16 |
from elixir import *
|
|
|
17 |
from sqlalchemy.sql.expression import func
|
| 18689 |
manas |
18 |
#from pyodbc import Row
|
| 16136 |
kshitij.so |
19 |
import Dial2VerifyFile
|
|
|
20 |
import optparse
|
|
|
21 |
|
|
|
22 |
parser = optparse.OptionParser()
|
|
|
23 |
parser.add_option("-d", "--d", dest="dbHost",
|
|
|
24 |
default="localhost",
|
|
|
25 |
type="string", help="The HOST where the database is running",
|
|
|
26 |
metavar="db_host")
|
|
|
27 |
|
|
|
28 |
(options, args) = parser.parse_args()
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
DB_USER = "root"
|
|
|
32 |
DB_PASSWORD = "shop2020"
|
|
|
33 |
DB_NAME = "dtr"
|
|
|
34 |
|
|
|
35 |
INSERT_QUERY= """
|
|
|
36 |
INSERT INTO dial2verifyStatus (session_id, api_key, mobile_number, verification_status, transaction_time, verification_time) VALUES ('%s', '%s', '%s', '%s', '%s', '%s');"""
|
|
|
37 |
|
| 16258 |
manas |
38 |
CHECK_VERIFIED_USERS="""
|
|
|
39 |
select a.id,a.verification_time from (select d.mobile_number,u.mobile_number as ue,u.id,u.email,d.verification_status, d.verification_time,u.mobile_number_last_updated, timediff(d.verification_time,u.mobile_number_last_updated) as ti,u.mobile_verified from dial2verifyStatus d join users u on d.mobile_number=u.mobile_number where d.verification_status='Verified' and u.mobile_verified!=1 and lower(u.referrer) not like 'emp%' and timediff(d.verification_time,u.mobile_number_last_updated) < time('00:05:00') and timediff(d.verification_time,u.mobile_number_last_updated) >= time('00:00:00')) a where a.mobile_number=a.ue and date(a.verification_time)<=(curdate() - interval 1 day) group by a.id;
|
|
|
40 |
"""
|
|
|
41 |
|
|
|
42 |
UPDATE_USER_VERIFIED_STATUS="""
|
|
|
43 |
update users set mobile_verified=1, mobile_number_last_updated='%s' where id=%s
|
|
|
44 |
"""
|
|
|
45 |
|
| 16136 |
kshitij.so |
46 |
def getDbConnection():
|
|
|
47 |
return MySQLdb.connect(options.dbHost, DB_USER, DB_PASSWORD, DB_NAME)
|
|
|
48 |
|
|
|
49 |
def insertVerificationData(filePath):
|
|
|
50 |
session_id=''
|
|
|
51 |
api_key=''
|
|
|
52 |
mobile_number_new=''
|
|
|
53 |
verifcation_status=''
|
|
|
54 |
transaction_time=None
|
|
|
55 |
verification_time=None
|
|
|
56 |
ttime=None
|
|
|
57 |
vtime=None
|
|
|
58 |
squery=''
|
|
|
59 |
wb = open_workbook(filePath)
|
|
|
60 |
conn = getDbConnection()
|
|
|
61 |
cur = conn.cursor()
|
|
|
62 |
s=wb.sheet_by_index(0)
|
|
|
63 |
for row in range(s.nrows):
|
|
|
64 |
for col in range(s.ncols):
|
|
|
65 |
if row==0:
|
|
|
66 |
continue
|
|
|
67 |
elif col==0:
|
|
|
68 |
session_id=s.cell(row,col).value
|
|
|
69 |
elif col==1:
|
|
|
70 |
api_key=s.cell(row,col).value
|
|
|
71 |
elif col==2:
|
|
|
72 |
mobile_number=s.cell(row,col).value
|
|
|
73 |
mobile_number_new =str(mobile_number)
|
|
|
74 |
elif col==3:
|
|
|
75 |
verifcation_status=s.cell(row,col).value
|
|
|
76 |
elif col==4:
|
|
|
77 |
transaction_time=s.cell(row,col).value
|
| 16216 |
manas |
78 |
ttime=datetime.strptime(transaction_time,'%m/%d/%Y %I:%M:%S %p')
|
| 16136 |
kshitij.so |
79 |
elif col==5:
|
|
|
80 |
verification_time=s.cell(row,col).value
|
|
|
81 |
if verification_time is not None and len(verification_time)>0:
|
| 16216 |
manas |
82 |
vtime=datetime.strptime(verification_time,'%m/%d/%Y %I:%M:%S %p')
|
| 16136 |
kshitij.so |
83 |
else:
|
|
|
84 |
vtime=None
|
|
|
85 |
if row>0:
|
|
|
86 |
if vtime is not None:
|
|
|
87 |
squery=INSERT_QUERY % (session_id,api_key,mobile_number_new[0:10],verifcation_status,ttime.strftime('%Y-%m-%d %H:%M:%S'),vtime.strftime('%Y-%m-%d %H:%M:%S'))
|
|
|
88 |
cur.execute(squery)
|
|
|
89 |
conn.commit()
|
|
|
90 |
else:
|
|
|
91 |
squery=INSERT_QUERY % (session_id,api_key,mobile_number_new[0:10],verifcation_status,ttime.strftime('%Y-%m-%d %H:%M:%S'),vtime)
|
|
|
92 |
cur.execute(squery)
|
|
|
93 |
conn.commit()
|
| 16258 |
manas |
94 |
conn.close()
|
|
|
95 |
|
| 16216 |
manas |
96 |
def deleteDial2VerifyRecords():
|
|
|
97 |
conn = getDbConnection()
|
|
|
98 |
datesql="delete from dial2verifyStatus"
|
|
|
99 |
cursor = conn.cursor()
|
|
|
100 |
cursor.execute(datesql)
|
| 16258 |
manas |
101 |
conn.commit()
|
|
|
102 |
conn.close()
|
|
|
103 |
|
|
|
104 |
def checkUsersStatus():
|
|
|
105 |
conn = getDbConnection()
|
|
|
106 |
datesql=CHECK_VERIFIED_USERS
|
|
|
107 |
cursor = conn.cursor()
|
|
|
108 |
cursor.execute(datesql)
|
|
|
109 |
result = cursor.fetchall()
|
|
|
110 |
for r in result:
|
|
|
111 |
updateUserStatus(r[0],r[1])
|
|
|
112 |
conn.close()
|
|
|
113 |
|
|
|
114 |
def updateUserStatus(userId,updateDate):
|
|
|
115 |
conn = getDbConnection()
|
|
|
116 |
datesql=UPDATE_USER_VERIFIED_STATUS%(updateDate,userId)
|
|
|
117 |
print datesql
|
|
|
118 |
cursor = conn.cursor()
|
|
|
119 |
cursor.execute(datesql)
|
|
|
120 |
conn.commit()
|
|
|
121 |
conn.close()
|
|
|
122 |
|
| 16136 |
kshitij.so |
123 |
|
|
|
124 |
def main():
|
|
|
125 |
filePath = Dial2VerifyFile.main()
|
| 16216 |
manas |
126 |
deleteDial2VerifyRecords()
|
| 16136 |
kshitij.so |
127 |
insertVerificationData(filePath)
|
| 16258 |
manas |
128 |
checkUsersStatus()
|
|
|
129 |
|
| 16136 |
kshitij.so |
130 |
if __name__ == '__main__':
|
| 16258 |
manas |
131 |
main()
|