| Line 3... |
Line 3... |
| 3 |
from datetime import datetime, timedelta
|
3 |
from datetime import datetime, timedelta
|
| 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
|
8 |
RetailerLinks, Activation_Codes, Agents,Agent_Roles,AgentLoginTimings
|
| 9 |
from dtr.utils import FetchLivePrices, DealSheet as X_DealSheet, \
|
9 |
from dtr.utils import FetchLivePrices, DealSheet as X_DealSheet, \
|
| 10 |
UserSpecificDeals
|
10 |
UserSpecificDeals
|
| 11 |
from dtr.utils.utils import getLogger
|
11 |
from dtr.utils.utils import getLogger
|
| 12 |
from elixir import *
|
12 |
from elixir import *
|
| 13 |
from sqlalchemy.sql.expression import or_
|
13 |
from sqlalchemy.sql.expression import or_
|
| Line 17... |
Line 17... |
| 17 |
import json
|
17 |
import json
|
| 18 |
import traceback
|
18 |
import traceback
|
| 19 |
import urllib
|
19 |
import urllib
|
| 20 |
import urllib2
|
20 |
import urllib2
|
| 21 |
import uuid
|
21 |
import uuid
|
| - |
|
22 |
from operator import and_
|
| 22 |
global RETAILER_DETAIL_CALL_COUNTER
|
23 |
global RETAILER_DETAIL_CALL_COUNTER
|
| 23 |
RETAILER_DETAIL_CALL_COUNTER = 0
|
24 |
RETAILER_DETAIL_CALL_COUNTER = 0
|
| 24 |
|
25 |
|
| 25 |
lgr = getLogger('/var/log/retailer-acquisition-api.log')
|
26 |
lgr = getLogger('/var/log/retailer-acquisition-api.log')
|
| 26 |
DEALER_RETRY_FACTOR = int(PythonPropertyReader.getConfig('DEALER_RETRY_FACTOR'))
|
27 |
DEALER_RETRY_FACTOR = int(PythonPropertyReader.getConfig('DEALER_RETRY_FACTOR'))
|
| Line 733... |
Line 734... |
| 733 |
else:
|
734 |
else:
|
| 734 |
self.retailer.next_call_time = self.callHistory.call_time + timedelta(days=7)
|
735 |
self.retailer.next_call_time = self.callHistory.call_time + timedelta(days=7)
|
| 735 |
self.callHistory.disposition_description = 'App link sent via' + self.callHistory.disposition_description + '. Followup again on ' + datetime.strftime(self.retailer.next_call_time, '%d/%m/%Y %H:%M:%S')
|
736 |
self.callHistory.disposition_description = 'App link sent via' + self.callHistory.disposition_description + '. Followup again on ' + datetime.strftime(self.retailer.next_call_time, '%d/%m/%Y %H:%M:%S')
|
| 736 |
session.commit()
|
737 |
session.commit()
|
| 737 |
return True
|
738 |
return True
|
| 738 |
|
- |
|
| 739 |
|
739 |
|
| - |
|
740 |
class Login():
|
| - |
|
741 |
|
| - |
|
742 |
def on_get(self, req, resp, agentId, role):
|
| - |
|
743 |
try:
|
| - |
|
744 |
if agentId or role is None:
|
| - |
|
745 |
resp.body = json.dumps({"result":{"success":"false","message":"Cannot not log out"}}, encoding='utf-8')
|
| - |
|
746 |
else:
|
| - |
|
747 |
lastLoginTime = session.query(Agents).filter(Agents.id==agentId).first()
|
| - |
|
748 |
AgentLoginTimings.loginTime=lastLoginTime.last_login
|
| - |
|
749 |
AgentLoginTimings.logoutTime=datetime.now()
|
| - |
|
750 |
AgentLoginTimings.role =role
|
| - |
|
751 |
AgentLoginTimings.agent_id = id
|
| - |
|
752 |
session.commit()
|
| - |
|
753 |
resp.body = json.dumps({"result":{"success":"true","message":"Success"}}, encoding='utf-8')
|
| - |
|
754 |
finally:
|
| - |
|
755 |
session.close()
|
| - |
|
756 |
|
| - |
|
757 |
def on_post(self,req,resp):
|
| - |
|
758 |
try:
|
| - |
|
759 |
jsonReq = json.loads(req.stream.read(), encoding='utf-8')
|
| - |
|
760 |
lgr.info( "Request ----\n" + str(jsonReq))
|
| - |
|
761 |
email=jsonReq.get('email')
|
| - |
|
762 |
password = jsonReq.get('password')
|
| - |
|
763 |
role=jsonReq.get('role')
|
| - |
|
764 |
checkUser = session.query(Agents.id).filter(and_(Agents.email==email,Agents.password==password)).first()
|
| - |
|
765 |
if checkUser is None:
|
| - |
|
766 |
print checkUser
|
| - |
|
767 |
resp.body = json.dumps({"result":{"success":"false","message":"Invalid User"}}, encoding='utf-8')
|
| - |
|
768 |
else:
|
| - |
|
769 |
print checkUser[0]
|
| - |
|
770 |
checkRole = session.query(Agent_Roles.id).filter(and_(Agent_Roles.agent_id==checkUser[0],Agent_Roles.role==role)).first()
|
| - |
|
771 |
if checkRole is None:
|
| - |
|
772 |
resp.body = json.dumps({"result":{"success":"false","message":"Invalid Role"}}, encoding='utf-8')
|
| - |
|
773 |
else:
|
| - |
|
774 |
Agents.last_login =datetime.now()
|
| - |
|
775 |
resp.body = json.dumps({"result":{"success":"true","message":"Valid User","id":checkUser[0]}}, encoding='utf-8')
|
| - |
|
776 |
session.commit()
|
| - |
|
777 |
finally:
|
| - |
|
778 |
session.close()
|
| - |
|
779 |
|
| - |
|
780 |
def test(self,email,password,role,resp):
|
| - |
|
781 |
checkUser = session.query(Agents.id).filter(and_(Agents.email==email,Agents.password==password)).first()
|
| - |
|
782 |
if checkUser is None:
|
| - |
|
783 |
print checkUser
|
| - |
|
784 |
resp.body = json.dumps({"result":{"success":"false","message":"Invalid User"}}, encoding='utf-8')
|
| - |
|
785 |
else:
|
| - |
|
786 |
print checkUser[0]
|
| - |
|
787 |
checkRole = session.query(Agent_Roles.id).filter(and_(Agent_Roles.agent_id==checkUser[0],Agent_Roles.role==role)).first()
|
| - |
|
788 |
if checkRole is None:
|
| - |
|
789 |
resp.body = json.dumps({"result":{"success":"false","message":"Invalid Role"}}, encoding='utf-8')
|
| - |
|
790 |
else:
|
| - |
|
791 |
resp.body = json.dumps({"result":{"success":"true","message":"Valid User"}}, encoding='utf-8')
|
| - |
|
792 |
|
| 740 |
def todict(obj, classkey=None):
|
793 |
def todict(obj, classkey=None):
|
| 741 |
if isinstance(obj, dict):
|
794 |
if isinstance(obj, dict):
|
| 742 |
data = {}
|
795 |
data = {}
|
| 743 |
for (k, v) in obj.items():
|
796 |
for (k, v) in obj.items():
|
| 744 |
data[k] = todict(v, classkey)
|
797 |
data[k] = todict(v, classkey)
|
| Line 778... |
Line 831... |
| 778 |
#def update_pin():
|
831 |
#def update_pin():
|
| 779 |
|
832 |
|
| 780 |
|
833 |
|
| 781 |
class Mock(object):
|
834 |
class Mock(object):
|
| 782 |
pass
|
835 |
pass
|
| 783 |
|
- |
|
| 784 |
def main():
|
- |
|
| 785 |
print make_tiny("http://www.google.com")
|
- |
|
| 786 |
|
836 |
|
| - |
|
837 |
def main():
|
| - |
|
838 |
print make_tiny("http://www.google.com")
|
| 787 |
if __name__ == '__main__':
|
839 |
if __name__ == '__main__':
|
| 788 |
main()
|
840 |
main()
|
| 789 |
|
841 |
|
| 790 |
|
842 |
|