| Line 4... |
Line 4... |
| 4 |
from dtr import main
|
4 |
from dtr import main
|
| 5 |
from dtr.config import PythonPropertyReader
|
5 |
from dtr.config import PythonPropertyReader
|
| 6 |
from dtr.storage import Mongo
|
6 |
from dtr.storage import Mongo
|
| 7 |
from dtr.storage.DataService import Retailers, Users, CallHistory, RetryConfig, \
|
7 |
from dtr.storage.DataService import Retailers, Users, CallHistory, RetryConfig, \
|
| 8 |
RetailerLinks, Activation_Codes, Agents, Agent_Roles, AgentLoginTimings, \
|
8 |
RetailerLinks, Activation_Codes, Agents, Agent_Roles, AgentLoginTimings, \
|
| 9 |
FetchDataHistory, RetailerContacts
|
9 |
FetchDataHistory, RetailerContacts, Orders
|
| - |
|
10 |
from dtr.storage.Mongo import get_mongo_connection
|
| - |
|
11 |
from dtr.storage.Mysql import fetchResult
|
| 10 |
from dtr.utils import FetchLivePrices, DealSheet as X_DealSheet, \
|
12 |
from dtr.utils import FetchLivePrices, DealSheet as X_DealSheet, \
|
| 11 |
UserSpecificDeals
|
13 |
UserSpecificDeals
|
| 12 |
from dtr.utils.utils import getLogger
|
14 |
from dtr.utils.utils import getLogger
|
| 13 |
from elixir import *
|
15 |
from elixir import *
|
| 14 |
from operator import and_
|
16 |
from operator import and_
|
| 15 |
from sqlalchemy.sql.expression import func, func, or_
|
17 |
from sqlalchemy.sql.expression import func, func, or_
|
| 16 |
from urllib import urlencode
|
18 |
from urllib import urlencode
|
| 17 |
import contextlib
|
19 |
import contextlib
|
| 18 |
import falcon
|
20 |
import falcon
|
| 19 |
import json
|
21 |
import json
|
| - |
|
22 |
import re
|
| 20 |
import string
|
23 |
import string
|
| 21 |
import traceback
|
24 |
import traceback
|
| 22 |
import urllib
|
25 |
import urllib
|
| 23 |
import urllib2
|
26 |
import urllib2
|
| 24 |
import uuid
|
27 |
import uuid
|
| 25 |
import re
|
- |
|
| 26 |
alphalist = list(string.uppercase)
|
28 |
alphalist = list(string.uppercase)
|
| 27 |
alphalist.remove('O')
|
29 |
alphalist.remove('O')
|
| 28 |
numList = ['1','2','3','4','5','6','7','8','9']
|
30 |
numList = ['1','2','3','4','5','6','7','8','9']
|
| 29 |
codesys = [alphalist, alphalist, numList, numList, numList]
|
31 |
codesys = [alphalist, alphalist, numList, numList, numList]
|
| 30 |
CONTACT_PRIORITY = ['sms', 'called', 'ringing']
|
32 |
CONTACT_PRIORITY = ['sms', 'called', 'ringing']
|
| 31 |
|
- |
|
| - |
|
33 |
RETRY_MAP = {'fresh':'retry', 'folluwpup':'fretry', 'onboarding':'oretry'}
|
| - |
|
34 |
ASSIGN_MAP = {'retry':'assigned', 'fretry':'fassigned', 'oretry':'oassigned'}
|
| 32 |
|
35 |
|
| 33 |
def getNextCode(codesys, code=None):
|
36 |
def getNextCode(codesys, code=None):
|
| 34 |
if code is None:
|
37 |
if code is None:
|
| 35 |
code = []
|
38 |
code = []
|
| 36 |
for charcode in codesys:
|
39 |
for charcode in codesys:
|
| Line 533... |
Line 536... |
| 533 |
|
536 |
|
| 534 |
|
537 |
|
| 535 |
class RetailerDetail():
|
538 |
class RetailerDetail():
|
| 536 |
global RETAILER_DETAIL_CALL_COUNTER
|
539 |
global RETAILER_DETAIL_CALL_COUNTER
|
| 537 |
def getRetryRetailer(self,failback=True):
|
540 |
def getRetryRetailer(self,failback=True):
|
| 538 |
retailer = None
|
- |
|
| 539 |
status = 'fretry' if self.callType == 'followup' else 'retry'
|
541 |
status = RETRY_MAP.get(self.callType)
|
| 540 |
retailer = session.query(Retailers).filter_by(status=status).filter(Retailers.next_call_time<=datetime.now()).order_by(Retailers.call_priority).order_by(Retailers.next_call_time).with_lockmode("update").first()
|
542 |
retailer = session.query(Retailers).filter_by(status=status).filter(Retailers.next_call_time<=datetime.now()).order_by(Retailers.call_priority).order_by(Retailers.next_call_time).with_lockmode("update").first()
|
| 541 |
if retailer is not None:
|
543 |
if retailer is not None:
|
| 542 |
lgr.info( "getRetryRetailer " + str(retailer.id))
|
544 |
lgr.info( "getRetryRetailer " + str(retailer.id))
|
| 543 |
else:
|
545 |
else:
|
| 544 |
if failback:
|
546 |
if failback:
|
| 545 |
retailer = self.getNewRetailer(False)
|
547 |
retailer = self.getNewRetailer(False)
|
| 546 |
return retailer
|
548 |
return retailer
|
| 547 |
if status=='retry':
|
- |
|
| 548 |
retailer.status = 'assigned'
|
- |
|
| 549 |
else:
|
- |
|
| 550 |
retailer.status = 'fassigned'
|
549 |
retailer.status = ASSIGN_MAP.get(status)
|
| 551 |
lgr.info( "getRetryRetailer " + str(retailer.id))
|
550 |
lgr.info( "getRetryRetailer " + str(retailer.id))
|
| 552 |
return retailer
|
551 |
return retailer
|
| 553 |
|
552 |
|
| 554 |
def getNewRetailer(self,failback=True):
|
553 |
def getNewRetailer(self,failback=True):
|
| 555 |
retry = True
|
554 |
retry = True
|
| Line 559... |
Line 558... |
| 559 |
lgr.info( "Calltype " + self.callType)
|
558 |
lgr.info( "Calltype " + self.callType)
|
| 560 |
status=self.callType
|
559 |
status=self.callType
|
| 561 |
query = session.query(Retailers).filter(Retailers.status==status)
|
560 |
query = session.query(Retailers).filter(Retailers.status==status)
|
| 562 |
if status=='fresh':
|
561 |
if status=='fresh':
|
| 563 |
query = query.filter_by(is_or=False, is_std=False).filter(or_(Retailers.agent_id==self.agentId, Retailers.agent_id==None)).order_by(Retailers.is_elavated.desc(), -Retailers.agent_id)
|
562 |
query = query.filter_by(is_or=False, is_std=False).filter(or_(Retailers.agent_id==self.agentId, Retailers.agent_id==None)).order_by(Retailers.is_elavated.desc(), -Retailers.agent_id)
|
| 564 |
else:
|
563 |
elif status=='followup':
|
| 565 |
query = query.filter(Retailers.next_call_time<=datetime.now()).order_by(Retailers.next_call_time)
|
564 |
query = query.filter(Retailers.next_call_time<=datetime.now()).order_by(Retailers.next_call_time)
|
| - |
|
565 |
else:
|
| - |
|
566 |
query = query.filter(Retailers.modified<=datetime.now()).order_by(Retailers.modified)
|
| - |
|
567 |
|
| 566 |
retailer = query.with_lockmode("update").first()
|
568 |
retailer = query.with_lockmode("update").first()
|
| 567 |
if retailer is not None:
|
569 |
if retailer is not None:
|
| 568 |
lgr.info( "retailer " +str(retailer.id))
|
570 |
lgr.info( "retailer " +str(retailer.id))
|
| 569 |
if status=="fresh":
|
571 |
if status=="fresh":
|
| 570 |
userquery = session.query(Users)
|
572 |
userquery = session.query(Users)
|
| Line 577... |
Line 579... |
| 577 |
retailer.status = 'alreadyuser'
|
579 |
retailer.status = 'alreadyuser'
|
| 578 |
lgr.info( "retailer.status " + retailer.status)
|
580 |
lgr.info( "retailer.status " + retailer.status)
|
| 579 |
session.commit()
|
581 |
session.commit()
|
| 580 |
continue
|
582 |
continue
|
| 581 |
retailer.status = 'assigned'
|
583 |
retailer.status = 'assigned'
|
| 582 |
else:
|
584 |
elif status=='followup':
|
| 583 |
if isActivated(retailer.id):
|
585 |
if isActivated(retailer.id):
|
| 584 |
print "Retailer Already %d activated and marked onboarded"%(retailer.id)
|
586 |
print "Retailer Already %d activated and marked onboarded"%(retailer.id)
|
| 585 |
continue
|
587 |
continue
|
| 586 |
retailer.status = 'fassigned'
|
588 |
retailer.status = 'fassigned'
|
| - |
|
589 |
else:
|
| - |
|
590 |
retailer.status = 'oassigned'
|
| 587 |
retailer.retry_count = 0
|
591 |
retailer.retry_count = 0
|
| 588 |
retailer.invalid_retry_count = 0
|
592 |
retailer.invalid_retry_count = 0
|
| 589 |
lgr.info( "Found Retailer " + str(retailer.id) + " with status " + status + " assigned to " + str(self.agentId))
|
593 |
lgr.info( "Found Retailer " + str(retailer.id) + " with status " + status + " assigned to " + str(self.agentId))
|
| 590 |
|
594 |
|
| 591 |
else:
|
595 |
else:
|
| Line 645... |
Line 649... |
| 645 |
fetchInfo.last_action = 'disposition'
|
649 |
fetchInfo.last_action = 'disposition'
|
| 646 |
fetchInfo.last_action_time = last_disposition.created
|
650 |
fetchInfo.last_action_time = last_disposition.created
|
| 647 |
fetchInfo.retailer_id = retailer.id
|
651 |
fetchInfo.retailer_id = retailer.id
|
| 648 |
session.commit()
|
652 |
session.commit()
|
| 649 |
|
653 |
|
| 650 |
otherContacts = [r for r, in session.query(RetailerContacts.mobile_number).filter_by(retailer_id=retailer.id).order_by(RetailerContacts.contact_type).all()]
|
654 |
otherContacts = [r for r, in session.query(RetailerContacts.mobile_number).filter_by(retailer_id=retailer.id).order_by(RetailerContacts.contact_type).all()]
|
| 651 |
resp.body = json.dumps(todict(getRetailerObj(retailer, otherContacts)), encoding='utf-8')
|
655 |
resp.body = json.dumps(todict(getRetailerObj(retailer, otherContacts, self.callType)), encoding='utf-8')
|
| 652 |
|
656 |
|
| 653 |
return
|
657 |
return
|
| 654 |
|
658 |
|
| 655 |
finally:
|
659 |
finally:
|
| 656 |
session.close()
|
660 |
session.close()
|
| 657 |
|
661 |
|
| 658 |
if retailer is None:
|
662 |
if retailer is None:
|
| 659 |
resp.body = "{}"
|
663 |
resp.body = "{}"
|
| 660 |
else:
|
664 |
else:
|
| - |
|
665 |
print "It should never come here"
|
| 661 |
resp.body = json.dumps(todict(getRetailerObj(retailer)), encoding='utf-8')
|
666 |
resp.body = json.dumps(todict(getRetailerObj(retailer)), encoding='utf-8')
|
| 662 |
|
667 |
|
| 663 |
|
668 |
|
| 664 |
def on_post(self, req, resp, agentId, callType):
|
669 |
def on_post(self, req, resp, agentId, callType):
|
| 665 |
returned = False
|
670 |
returned = False
|
| Line 839... |
Line 844... |
| 839 |
else:
|
844 |
else:
|
| 840 |
mapped_with = 'code'
|
845 |
mapped_with = 'code'
|
| 841 |
retailerLink.mapped_with = mapped_with
|
846 |
retailerLink.mapped_with = mapped_with
|
| 842 |
retailerLink.user_id = user.id
|
847 |
retailerLink.user_id = user.id
|
| 843 |
retailer = session.query(Retailers).filter_by(id=retailerId).first()
|
848 |
retailer = session.query(Retailers).filter_by(id=retailerId).first()
|
| 844 |
retailer.status = 'onboarded'
|
849 |
retailer.status = 'onboarding'
|
| 845 |
session.commit()
|
850 |
session.commit()
|
| 846 |
print "retailerLink.retailer_id", retailerLink.retailer_id
|
851 |
print "retailerLink.retailer_id", retailerLink.retailer_id
|
| 847 |
session.close()
|
852 |
session.close()
|
| 848 |
return True
|
853 |
return True
|
| 849 |
|
854 |
|
| Line 870... |
Line 875... |
| 870 |
retailerContact.call_type = callType
|
875 |
retailerContact.call_type = callType
|
| 871 |
retailerContact.contact_type = contactType
|
876 |
retailerContact.contact_type = contactType
|
| 872 |
retailerContact.mobile_number = mobile
|
877 |
retailerContact.mobile_number = mobile
|
| 873 |
else:
|
878 |
else:
|
| 874 |
if CONTACT_PRIORITY.index(retailerContact.contact_type) > CONTACT_PRIORITY.index(contactType):
|
879 |
if CONTACT_PRIORITY.index(retailerContact.contact_type) > CONTACT_PRIORITY.index(contactType):
|
| 875 |
retailerContact.contact_type = callType
|
880 |
retailerContact.contact_type = contactType
|
| 876 |
|
881 |
|
| 877 |
|
882 |
|
| 878 |
|
883 |
|
| 879 |
class Login():
|
884 |
class Login():
|
| 880 |
|
885 |
|
| Line 971... |
Line 976... |
| 971 |
if retailer is not None:
|
976 |
if retailer is not None:
|
| 972 |
retailerLink = session.query(RetailerLinks).filter_by(retailer_id=retailer.id).first()
|
977 |
retailerLink = session.query(RetailerLinks).filter_by(retailer_id=retailer.id).first()
|
| 973 |
if retailerLink is not None:
|
978 |
if retailerLink is not None:
|
| 974 |
retailerLink.user_id = user.id
|
979 |
retailerLink.user_id = user.id
|
| 975 |
retailerLink.mapped_with=mappedWith
|
980 |
retailerLink.mapped_with=mappedWith
|
| 976 |
retailer.status = 'onboarded'
|
981 |
retailer.status = 'onboarding'
|
| 977 |
result = True
|
982 |
result = True
|
| 978 |
session.commit()
|
983 |
session.commit()
|
| 979 |
return result
|
984 |
return result
|
| 980 |
finally:
|
985 |
finally:
|
| 981 |
session.close()
|
986 |
session.close()
|
| Line 999... |
Line 1004... |
| 999 |
data[classkey] = obj.__class__.__name__
|
1004 |
data[classkey] = obj.__class__.__name__
|
| 1000 |
return data
|
1005 |
return data
|
| 1001 |
else:
|
1006 |
else:
|
| 1002 |
return obj
|
1007 |
return obj
|
| 1003 |
|
1008 |
|
| 1004 |
def getRetailerObj(retailer, otherContacts1=None):
|
1009 |
def getRetailerObj(retailer, otherContacts1=None, callType=None):
|
| 1005 |
print "before otherContacts1",otherContacts1
|
1010 |
print "before otherContacts1",otherContacts1
|
| 1006 |
otherContacts = [] if otherContacts1 is None else otherContacts1
|
1011 |
otherContacts = [] if otherContacts1 is None else otherContacts1
|
| 1007 |
print "afotherContacts1",otherContacts
|
1012 |
print "afotherContacts1",otherContacts
|
| 1008 |
obj = Mock()
|
1013 |
obj = Mock()
|
| 1009 |
obj.title = retailer.title
|
1014 |
obj.title = retailer.title
|
| Line 1016... |
Line 1021... |
| 1016 |
obj.contact1 = None if len(otherContacts)==0 else otherContacts[0]
|
1021 |
obj.contact1 = None if len(otherContacts)==0 else otherContacts[0]
|
| 1017 |
if obj.contact1 is not None:
|
1022 |
if obj.contact1 is not None:
|
| 1018 |
obj.contact2 = None if len(otherContacts)==1 else otherContacts[1]
|
1023 |
obj.contact2 = None if len(otherContacts)==1 else otherContacts[1]
|
| 1019 |
obj.scheduled = (retailer.call_priority is not None)
|
1024 |
obj.scheduled = (retailer.call_priority is not None)
|
| 1020 |
obj.status = retailer.status
|
1025 |
obj.status = retailer.status
|
| - |
|
1026 |
if callType == 'onboarding':
|
| - |
|
1027 |
try:
|
| - |
|
1028 |
userId, = session.query(RetailerLinks.user_id).filter(RetailerLinks.retailer_id==retailer.id).first()
|
| - |
|
1029 |
obj.userId = userId
|
| - |
|
1030 |
result = fetchResult("select * from useractive where user_id=%d"%(userId))
|
| - |
|
1031 |
if result == ():
|
| - |
|
1032 |
obj.last_active = None
|
| - |
|
1033 |
else:
|
| - |
|
1034 |
obj.last_active =datetime.strftime(result[0][0], '%d/%m/%Y %H:%M:%S')
|
| - |
|
1035 |
ordersCount = session.query(Orders).filter_by(user_id = userId).filter(~Orders.status.in_('ORDER_NOT_CREATED_KNOWN', 'ORDER_ALREADY_CREATED_IGNORED')).count()
|
| - |
|
1036 |
obj.orders = ordersCount
|
| - |
|
1037 |
finally:
|
| - |
|
1038 |
session.close()
|
| 1021 |
return obj
|
1039 |
return obj
|
| 1022 |
|
1040 |
|
| 1023 |
def make_tiny(code):
|
1041 |
def make_tiny(code):
|
| 1024 |
url = 'https://play.google.com/store/apps/details?id=com.saholic.profittill&referrer=utm_source%3D0%26utm_medium%3DCRM%26utm_term%3D001%26utm_campaign%3D' + code
|
1042 |
url = 'https://play.google.com/store/apps/details?id=com.saholic.profittill&referrer=utm_source%3D0%26utm_medium%3DCRM%26utm_term%3D001%26utm_campaign%3D' + code
|
| 1025 |
request_url = ('http://tinyurl.com/api-create.php?' + urlencode({'url':url}))
|
1043 |
request_url = ('http://tinyurl.com/api-create.php?' + urlencode({'url':url}))
|
| Line 1058... |
Line 1076... |
| 1058 |
resp.body = json.dumps({"Retailers":retailersJsonArray}, encoding='utf-8')
|
1076 |
resp.body = json.dumps({"Retailers":retailersJsonArray}, encoding='utf-8')
|
| 1059 |
return
|
1077 |
return
|
| 1060 |
finally:
|
1078 |
finally:
|
| 1061 |
session.close()
|
1079 |
session.close()
|
| 1062 |
|
1080 |
|
| 1063 |
|
- |
|
| 1064 |
#def update_pin():
|
- |
|
| 1065 |
|
- |
|
| 1066 |
|
1081 |
|
| 1067 |
class Mock(object):
|
1082 |
class Mock(object):
|
| 1068 |
pass
|
1083 |
pass
|
| 1069 |
|
1084 |
|
| 1070 |
def tagActivatedReatilers():
|
1085 |
def tagActivatedReatilers():
|