| Line 7... |
Line 7... |
| 7 |
from dtr.storage import Mongo
|
7 |
from dtr.storage import Mongo
|
| 8 |
from dtr.storage.DataService import Retailers, Users, CallHistory, RetryConfig, \
|
8 |
from dtr.storage.DataService import Retailers, Users, CallHistory, RetryConfig, \
|
| 9 |
RetailerLinks, Activation_Codes, Agents, Agent_Roles, AgentLoginTimings, \
|
9 |
RetailerLinks, Activation_Codes, Agents, Agent_Roles, AgentLoginTimings, \
|
| 10 |
FetchDataHistory, RetailerContacts, Orders, OnboardedRetailerChecklists,\
|
10 |
FetchDataHistory, RetailerContacts, Orders, OnboardedRetailerChecklists,\
|
| 11 |
RetailerAddresses, Pincodeavailability, app_offers, appmasters, user_app_cashbacks, user_app_installs,\
|
11 |
RetailerAddresses, Pincodeavailability, app_offers, appmasters, user_app_cashbacks, user_app_installs,\
|
| 12 |
Postoffices
|
12 |
Postoffices, UserMasterData
|
| 13 |
from dtr.storage.Mongo import get_mongo_connection
|
13 |
from dtr.storage.Mongo import get_mongo_connection
|
| 14 |
from dtr.storage.Mysql import fetchResult
|
14 |
from dtr.storage.Mysql import fetchResult
|
| 15 |
from dtr.utils import FetchLivePrices, DealSheet as X_DealSheet, \
|
15 |
from dtr.utils import FetchLivePrices, DealSheet as X_DealSheet, \
|
| 16 |
UserSpecificDeals
|
16 |
UserSpecificDeals
|
| 17 |
from dtr.utils.utils import getLogger,encryptMessage,decryptMessage
|
17 |
from dtr.utils.utils import getLogger,encryptMessage,decryptMessage,\
|
| - |
|
18 |
get_mongo_connection_dtr_data, to_java_date
|
| 18 |
from elixir import *
|
19 |
from elixir import *
|
| 19 |
from operator import and_
|
20 |
from operator import and_
|
| 20 |
from sqlalchemy.sql.expression import func, func, or_, desc, asc, case
|
21 |
from sqlalchemy.sql.expression import func, func, or_, desc, asc, case
|
| 21 |
from urllib import urlencode
|
22 |
from urllib import urlencode
|
| 22 |
import contextlib
|
23 |
import contextlib
|
| Line 1134... |
Line 1135... |
| 1134 |
if classkey is not None and hasattr(obj, "__class__"):
|
1135 |
if classkey is not None and hasattr(obj, "__class__"):
|
| 1135 |
data[classkey] = obj.__class__.__name__
|
1136 |
data[classkey] = obj.__class__.__name__
|
| 1136 |
return data
|
1137 |
return data
|
| 1137 |
else:
|
1138 |
else:
|
| 1138 |
return obj
|
1139 |
return obj
|
| 1139 |
|
1140 |
|
| 1140 |
def getRetailerObj(retailer, otherContacts1=None, callType=None):
|
1141 |
def getRetailerObj(retailer, otherContacts1=None, callType=None):
|
| 1141 |
print "before otherContacts1",otherContacts1
|
1142 |
print "before otherContacts1",otherContacts1
|
| 1142 |
otherContacts = [] if otherContacts1 is None else otherContacts1
|
1143 |
otherContacts = [] if otherContacts1 is None else otherContacts1
|
| 1143 |
print "after otherContacts1",otherContacts
|
1144 |
print "after otherContacts1",otherContacts
|
| 1144 |
obj = Mock()
|
1145 |
obj = Mock()
|
| Line 1615... |
Line 1616... |
| 1615 |
decrypted_data = decryptMessage(decryption_data)
|
1616 |
decrypted_data = decryptMessage(decryption_data)
|
| 1616 |
resp.body = json.dumps({"result":{"value":decrypted_data}}, encoding='utf-8')
|
1617 |
resp.body = json.dumps({"result":{"value":decrypted_data}}, encoding='utf-8')
|
| 1617 |
|
1618 |
|
| 1618 |
else:
|
1619 |
else:
|
| 1619 |
resp.body = json.dumps({}, encoding='utf-8')
|
1620 |
resp.body = json.dumps({}, encoding='utf-8')
|
| - |
|
1621 |
|
| - |
|
1622 |
class GetUserCrmApplication:
|
| - |
|
1623 |
|
| - |
|
1624 |
def on_get(self,req,resp):
|
| - |
|
1625 |
project_name = req.get_param("project_name")
|
| - |
|
1626 |
if project_name == 'accessories':
|
| - |
|
1627 |
user = session.query(UserMasterData).filter_by(project_id=1).filter(or_(UserMasterData.next_call_time<=datetime.now(),UserMasterData.status=='new')).filter(UserMasterData.pincode_servicable==True).order_by(UserMasterData.next_call_time).order_by(UserMasterData.id).with_lockmode("update").first()
|
| - |
|
1628 |
#.filter(UserMasterData.modified<=(datetime.now()-timedelta(days=3)))
|
| - |
|
1629 |
if user is None:
|
| - |
|
1630 |
fetchUserMasterData()
|
| - |
|
1631 |
else:
|
| - |
|
1632 |
resp.body = json.dumps(todict(getUserObject(user)), encoding='utf-8')
|
| - |
|
1633 |
|
| - |
|
1634 |
def fetchUserMasterData():
|
| - |
|
1635 |
#First check from the table whether data is present or not UserMasterData
|
| - |
|
1636 |
#If Data is empty then fetch the details using getCartDetailsUser
|
| - |
|
1637 |
getCartDetailsUser()
|
| - |
|
1638 |
|
| - |
|
1639 |
def getCartDetailsUser():
|
| - |
|
1640 |
userList=[]
|
| - |
|
1641 |
orderUserList=[]
|
| - |
|
1642 |
userMasterMap={}
|
| - |
|
1643 |
queryfilter = {"$and":
|
| - |
|
1644 |
[
|
| - |
|
1645 |
{'created':{"$gte":(to_java_date(datetime.now())-5*86400000)}},
|
| - |
|
1646 |
{'created':{"$lte":(to_java_date(datetime.now())- 43200000)}},
|
| - |
|
1647 |
{"url":{"$regex" : "http://api.profittill.com/cartdetails"}}
|
| - |
|
1648 |
]
|
| - |
|
1649 |
}
|
| - |
|
1650 |
result = get_mongo_connection_dtr_data().User.browsinghistories.find(queryfilter).distinct('user_id')
|
| - |
|
1651 |
|
| - |
|
1652 |
for r in result:
|
| - |
|
1653 |
userList.append(r)
|
| - |
|
1654 |
|
| - |
|
1655 |
myquery = "select user_id from allorder where store_id='spice' and (category='Accs' or category='Accessories') and user_id in (%s)" % ",".join(map(str,userList))
|
| - |
|
1656 |
|
| - |
|
1657 |
result = fetchResult(myquery)
|
| - |
|
1658 |
for r in result:
|
| - |
|
1659 |
orderUserList.append(r)
|
| - |
|
1660 |
|
| - |
|
1661 |
finalUserList = list(set(userList) - set(orderUserList))
|
| - |
|
1662 |
|
| - |
|
1663 |
queryfilternew = {"$and":
|
| - |
|
1664 |
[
|
| - |
|
1665 |
{'user_id':{"$in":finalUserList}},
|
| - |
|
1666 |
{'created':{"$gte":(to_java_date(datetime.now())-5*86400000)}},
|
| - |
|
1667 |
{'created':{"$lte":(to_java_date(datetime.now())- 43200000)}},
|
| - |
|
1668 |
{"url":{"$regex" : "http://api.profittill.com/cartdetails"}}
|
| - |
|
1669 |
]
|
| - |
|
1670 |
}
|
| - |
|
1671 |
itemIds = list(get_mongo_connection_dtr_data().User.browsinghistories.find(queryfilternew))
|
| - |
|
1672 |
|
| - |
|
1673 |
for i in itemIds:
|
| - |
|
1674 |
if(userMasterMap.has_key(i.get('user_id'))):
|
| - |
|
1675 |
if userMasterMap.get(i.get('user_id')) > i.get('created'):
|
| - |
|
1676 |
userMasterMap[i.get('user_id')]=i.get('created')
|
| - |
|
1677 |
else:
|
| - |
|
1678 |
userMasterMap[i.get('user_id')]=i.get('created')
|
| - |
|
1679 |
|
| - |
|
1680 |
d_sorted = sorted(zip(userMasterMap.values(), userMasterMap.keys()))
|
| - |
|
1681 |
|
| - |
|
1682 |
for i in range(0,20):
|
| - |
|
1683 |
userId=d_sorted[i][1]
|
| - |
|
1684 |
userMasterData = UserMasterData()
|
| - |
|
1685 |
userMasterData.user_id = userId
|
| - |
|
1686 |
userMasterData.project_id = 1
|
| - |
|
1687 |
userMasterData.contact1 = getUserContactDetails(userId)
|
| - |
|
1688 |
userMasterData.counter = 0
|
| - |
|
1689 |
userMasterData.created = datetime.now()
|
| - |
|
1690 |
userMasterData.modified = datetime.now()
|
| - |
|
1691 |
userMasterData.status = 'new'
|
| - |
|
1692 |
userMasterData.pincode_servicable = checkPincodeServicable(userId)
|
| - |
|
1693 |
session.commit()
|
| - |
|
1694 |
session.close()
|
| - |
|
1695 |
|
| - |
|
1696 |
def getUserContactDetails(userId):
|
| - |
|
1697 |
r = session.query(Users.mobile_number).filter_by(id=userId).first()
|
| - |
|
1698 |
if r is None:
|
| - |
|
1699 |
return None
|
| - |
|
1700 |
else:
|
| - |
|
1701 |
return r[0]
|
| - |
|
1702 |
|
| - |
|
1703 |
def checkPincodeServicable(userId):
|
| - |
|
1704 |
checkAddressUser = "select distinct pincode from all_user_addresses where user_id= (%s)"
|
| - |
|
1705 |
result = fetchResult(checkAddressUser,userId)
|
| - |
|
1706 |
if len(result)==0:
|
| - |
|
1707 |
return True
|
| - |
|
1708 |
else:
|
| - |
|
1709 |
myquery = "select count(*) from (select distinct pincode from all_user_addresses where user_id= (%s))a join pincodeavailability p on a.pincode=p.code"
|
| - |
|
1710 |
result = fetchResult(myquery,userId)
|
| - |
|
1711 |
if result[0][0]==0:
|
| - |
|
1712 |
return False
|
| - |
|
1713 |
else:
|
| - |
|
1714 |
return True
|
| - |
|
1715 |
|
| - |
|
1716 |
def getUserObject(user):
|
| - |
|
1717 |
obj = Mock()
|
| - |
|
1718 |
obj.user_id = user.user_id
|
| - |
|
1719 |
result = fetchResult("select * from useractive where user_id=%d"%(user.user_id))
|
| - |
|
1720 |
if result == ():
|
| - |
|
1721 |
obj.last_active = None
|
| - |
|
1722 |
else:
|
| - |
|
1723 |
obj.last_active =datetime.strftime(result[0][1], '%d/%m/%Y %H:%M:%S')
|
| - |
|
1724 |
|
| - |
|
1725 |
obj.contact = user.contact1
|
| - |
|
1726 |
obj.timeStamp=None
|
| - |
|
1727 |
|
| - |
|
1728 |
details = get_mongo_connection().Dtr.merchantOrder.find({"userId":user.user_id}).sort([("createdOn",-1)]).limit(1)
|
| - |
|
1729 |
for detail in details:
|
| - |
|
1730 |
obj.timeStamp= detail.get('createdOn')
|
| - |
|
1731 |
|
| - |
|
1732 |
obj.totalOrders = get_mongo_connection().Dtr.merchantOrder.find({"userId":user.user_id}).count()
|
| - |
|
1733 |
|
| - |
|
1734 |
return obj
|
| - |
|
1735 |
|
| - |
|
1736 |
def getCartTabsUser():
|
| - |
|
1737 |
userList=[]
|
| - |
|
1738 |
orderUserList=[]
|
| - |
|
1739 |
userMasterMap={}
|
| - |
|
1740 |
queryfilter = {"$and":
|
| - |
|
1741 |
[
|
| - |
|
1742 |
{'created':{"$gte":(to_java_date(datetime.now())-2*86400000)}},
|
| - |
|
1743 |
{'created':{"$lte":(to_java_date(datetime.now())- 43200000)}},
|
| - |
|
1744 |
{"url":{"$regex" : "http://api.profittill.com/category/6"}}
|
| - |
|
1745 |
]
|
| - |
|
1746 |
}
|
| - |
|
1747 |
result = get_mongo_connection_dtr_data().User.browsinghistories.find(queryfilter).distinct('user_id')
|
| - |
|
1748 |
|
| - |
|
1749 |
for r in result:
|
| - |
|
1750 |
userList.append(r)
|
| - |
|
1751 |
|
| - |
|
1752 |
|
| - |
|
1753 |
|
| - |
|
1754 |
myquery = "select user_id from allorder where store_id='spice' and (category='Accs' or category='Accessories') and user_id in (%s)" % ",".join(map(str,userList))
|
| - |
|
1755 |
|
| - |
|
1756 |
result = fetchResult(myquery)
|
| - |
|
1757 |
for r in result:
|
| - |
|
1758 |
orderUserList.append(r)
|
| - |
|
1759 |
|
| - |
|
1760 |
finalUserList = list(set(userList) - set(orderUserList))
|
| - |
|
1761 |
|
| - |
|
1762 |
queryfilternew = {"$and":
|
| - |
|
1763 |
[
|
| - |
|
1764 |
{'user_id':{"$in":finalUserList}},
|
| - |
|
1765 |
{'created':{"$gte":(to_java_date(datetime.now())-2*86400000)}},
|
| - |
|
1766 |
{'created':{"$lte":(to_java_date(datetime.now())- 43200000)}},
|
| - |
|
1767 |
{"url":{"$regex" : "http://api.profittill.com/category/6"}}
|
| - |
|
1768 |
]
|
| - |
|
1769 |
}
|
| - |
|
1770 |
itemIds = list(get_mongo_connection_dtr_data().User.browsinghistories.find(queryfilternew))
|
| - |
|
1771 |
|
| - |
|
1772 |
for i in itemIds:
|
| - |
|
1773 |
if(userMasterMap.has_key(i.get('user_id'))):
|
| - |
|
1774 |
if userMasterMap.get(i.get('user_id')) > i.get('created'):
|
| - |
|
1775 |
userMasterMap[i.get('user_id')]=i.get('created')
|
| - |
|
1776 |
else:
|
| - |
|
1777 |
userMasterMap[i.get('user_id')]=i.get('created')
|
| - |
|
1778 |
|
| - |
|
1779 |
d_sorted = sorted(zip(userMasterMap.values(), userMasterMap.keys()))
|
| 1620 |
|
1780 |
|
| 1621 |
def main():
|
1781 |
def main():
|
| 1622 |
#tagActivatedReatilers()
|
1782 |
#tagActivatedReatilers()
|
| 1623 |
a = RetailerDetail()
|
1783 |
#a = RetailerDetail()
|
| 1624 |
retailer = a.getNotActiveRetailer()
|
1784 |
#retailer = a.getNotActiveRetailer()
|
| 1625 |
otherContacts = [r for r, in session.query(RetailerContacts.mobile_number).filter_by(retailer_id=retailer.id).order_by(RetailerContacts.contact_type).all()]
|
1785 |
#otherContacts = [r for r, in session.query(RetailerContacts.mobile_number).filter_by(retailer_id=retailer.id).order_by(RetailerContacts.contact_type).all()]
|
| 1626 |
print json.dumps(todict(getRetailerObj(retailer, otherContacts, 'fresh')), encoding='utf-8')
|
1786 |
#print json.dumps(todict(getRetailerObj(retailer, otherContacts, 'fresh')), encoding='utf-8')
|
| 1627 |
#print make_tiny("AA")
|
1787 |
#print make_tiny("AA")
|
| - |
|
1788 |
a = GetUserCrmApplication()
|
| - |
|
1789 |
a.getUser('accessories')
|
| 1628 |
|
1790 |
|
| 1629 |
if __name__ == '__main__':
|
1791 |
if __name__ == '__main__':
|
| 1630 |
main()
|
1792 |
main()
|
| 1631 |
|
1793 |
|
| 1632 |
|
1794 |
|