| Line 2... |
Line 2... |
| 2 |
from dtr.storage import DataService
|
2 |
from dtr.storage import DataService
|
| 3 |
from dtr.storage.DataService import app_offers, app_affiliates, appmasters
|
3 |
from dtr.storage.DataService import app_offers, app_affiliates, appmasters
|
| 4 |
from dtr.utils.utils import AFFILIATE_OFFER_API, AFFILIATE_OFFER_DESC_API, fetchResponseUsingProxy
|
4 |
from dtr.utils.utils import AFFILIATE_OFFER_API, AFFILIATE_OFFER_DESC_API, fetchResponseUsingProxy
|
| 5 |
import json
|
5 |
import json
|
| 6 |
import math
|
6 |
import math
|
| - |
|
7 |
from dtr.utils.MailSender import Email
|
| - |
|
8 |
import traceback
|
| 7 |
|
9 |
|
| 8 |
AFFILIATE_ID = 1
|
10 |
AFFILIATE_ID = 1
|
| 9 |
DEVICE_ID = "SpiceRetail"
|
11 |
DEVICE_ID = "SpiceRetail"
|
| 10 |
RETAILER_CODE = 123
|
12 |
RETAILER_CODE = 123
|
| 11 |
ACTIVE_OFFERS = []
|
13 |
ACTIVE_OFFERS = []
|
| 12 |
|
14 |
|
| 13 |
DataService.initialize(db_hostname='localhost' )
|
15 |
DataService.initialize(db_hostname='localhost' )
|
| 14 |
|
16 |
|
| - |
|
17 |
def _sendAlertForNewApp(packageName, appName):
|
| - |
|
18 |
m = Email('localhost')
|
| - |
|
19 |
mFrom = "dtr@shop2020.in"
|
| - |
|
20 |
m.setFrom(mFrom)
|
| - |
|
21 |
#mTo = ['rajneesh.arora@saholic.com','kshitij.sood@saholic.com','chaitnaya.vats@saholic.com','manoj.kumar@saholic.com','manish.sharma@shop2020.in']
|
| - |
|
22 |
mTo = ['manish.sharma@shop2020.in']
|
| - |
|
23 |
for receipient in mTo:
|
| - |
|
24 |
m.addRecipient(receipient)
|
| - |
|
25 |
|
| - |
|
26 |
m.setSubject("New App have been found:- Package Name:-"+ packageName+" App Name:- "+appName)
|
| - |
|
27 |
|
| - |
|
28 |
m.setTextBody(None)
|
| - |
|
29 |
|
| - |
|
30 |
m.send()
|
| - |
|
31 |
|
| 15 |
|
32 |
|
| 16 |
def dumpOffers():
|
33 |
def dumpOffers():
|
| 17 |
global ACTIVE_OFFERS
|
34 |
global ACTIVE_OFFERS
|
| 18 |
offer_url = AFFILIATE_OFFER_API.get(AFFILIATE_ID)%(DEVICE_ID,RETAILER_CODE)
|
35 |
offer_url = AFFILIATE_OFFER_API.get(AFFILIATE_ID)%(DEVICE_ID,RETAILER_CODE)
|
| 19 |
response = fetchResponseUsingProxy(offer_url, proxy=False)
|
36 |
response = fetchResponseUsingProxy(offer_url, proxy=False)
|
| Line 22... |
Line 39... |
| 22 |
offers = (input_json['payload'])['offers']
|
39 |
offers = (input_json['payload'])['offers']
|
| 23 |
for offer in offers:
|
40 |
for offer in offers:
|
| 24 |
ACTIVE_OFFERS.append(str(offer['offerId']))
|
41 |
ACTIVE_OFFERS.append(str(offer['offerId']))
|
| 25 |
|
42 |
|
| 26 |
print ACTIVE_OFFERS
|
43 |
print ACTIVE_OFFERS
|
| 27 |
allExistingOffers = app_offers.query.all()
|
- |
|
| 28 |
for existingOffer in allExistingOffers:
|
- |
|
| 29 |
existingOffer.offer_active = False
|
- |
|
| 30 |
existingOffer.show = False
|
- |
|
| 31 |
session.commit()
|
- |
|
| 32 |
|
44 |
|
| 33 |
for offer in offers:
|
45 |
for offer in offers:
|
| 34 |
fetchOfferDescriptionAndDump(offer)
|
46 |
fetchOfferDescriptionAndDump(offer)
|
| 35 |
|
47 |
|
| 36 |
|
48 |
|
| Line 43... |
Line 55... |
| 43 |
if app_master is None:
|
55 |
if app_master is None:
|
| 44 |
app_master = appmasters()
|
56 |
app_master = appmasters()
|
| 45 |
app_master.app_name = offer.get('appName')
|
57 |
app_master.app_name = offer.get('appName')
|
| 46 |
app_master.package_name = offer.get('packageName')
|
58 |
app_master.package_name = offer.get('packageName')
|
| 47 |
app_master.os_name = 'ANDROID'
|
59 |
app_master.os_name = 'ANDROID'
|
| - |
|
60 |
try:
|
| - |
|
61 |
_sendAlertForNewApp(offer.get('packageName'), offer.get('appName'))
|
| - |
|
62 |
except:
|
| - |
|
63 |
print traceback.print_exc()
|
| - |
|
64 |
|
| 48 |
session.commit()
|
65 |
session.commit()
|
| 49 |
appMasterId = app_master.id
|
66 |
appMasterId = app_master.id
|
| 50 |
app_offer = app_offers.query.filter(app_offers.affiliate_id==AFFILIATE_ID).filter(app_offers.affiliate_offer_id==offer['offerId']).filter(app_offers.package_name==offer['packageName']).first()
|
67 |
app_offer = app_offers.query.filter(app_offers.affiliate_id==AFFILIATE_ID).filter(app_offers.affiliate_offer_id==offer['offerId']).filter(app_offers.package_name==offer['packageName']).first()
|
| 51 |
|
68 |
|
| 52 |
if app_offer is None:
|
69 |
if app_offer is None:
|
| Line 76... |
Line 93... |
| 76 |
app_offer.offer_active = True
|
93 |
app_offer.offer_active = True
|
| 77 |
existingAppOffer = app_offers.query.filter(app_offers.affiliate_id==AFFILIATE_ID).filter(app_offers.package_name==offer['packageName']).filter(app_offers.show==True).first()
|
94 |
existingAppOffer = app_offers.query.filter(app_offers.affiliate_id==AFFILIATE_ID).filter(app_offers.package_name==offer['packageName']).filter(app_offers.show==True).first()
|
| 78 |
|
95 |
|
| 79 |
if existingAppOffer is None:
|
96 |
if existingAppOffer is None:
|
| 80 |
app_offer.show = True
|
97 |
app_offer.show = True
|
| 81 |
app_offer.offer_active = True
|
- |
|
| 82 |
else:
|
98 |
else:
|
| 83 |
if existingAppOffer.affiliate_offer_id not in ACTIVE_OFFERS:
|
99 |
if existingAppOffer.affiliate_offer_id not in ACTIVE_OFFERS:
|
| 84 |
existingAppOffer.show = False
|
100 |
existingAppOffer.show = False
|
| 85 |
app_offer.show = True
|
101 |
app_offer.show = True
|
| 86 |
app_offer.offer_active = True
|
- |
|
| 87 |
else:
|
102 |
else:
|
| 88 |
if existingAppOffer.offer_price <= float(offer['offerPrice']):
|
103 |
if existingAppOffer.offer_price <= float(offer['offerPrice']):
|
| 89 |
existingAppOffer.show = False
|
104 |
existingAppOffer.show = False
|
| 90 |
app_offer.show = True
|
105 |
app_offer.show = True
|
| 91 |
app_offer.offer_active = True
|
- |
|
| 92 |
else:
|
106 |
else:
|
| 93 |
existingAppOffer.show = True
|
107 |
existingAppOffer.show = True
|
| 94 |
existingAppOffer.offer_active = True
|
108 |
existingAppOffer.offer_active = True
|
| 95 |
app_offer.show = False
|
109 |
app_offer.show = False
|
| 96 |
else:
|
110 |
else:
|
| Line 106... |
Line 120... |
| 106 |
app_offer.offerCategory = offer.get('offerCategory')
|
120 |
app_offer.offerCategory = offer.get('offerCategory')
|
| 107 |
app_offer.promoImage = input_json.get('promoImage')
|
121 |
app_offer.promoImage = input_json.get('promoImage')
|
| 108 |
app_offer.ratings = offer.get('appRating')
|
122 |
app_offer.ratings = offer.get('appRating')
|
| 109 |
app_offer.downloads = offer.get('appDownloads')
|
123 |
app_offer.downloads = offer.get('appDownloads')
|
| 110 |
app_offer.image_url = offer.get('iconUrl')
|
124 |
app_offer.image_url = offer.get('iconUrl')
|
| - |
|
125 |
app_offer.offer_active = True
|
| 111 |
existingAppOffer = app_offers.query.filter(app_offers.affiliate_id==AFFILIATE_ID).filter(app_offers.package_name==offer['packageName']).filter(app_offers.show==True).first()
|
126 |
existingAppOffer = app_offers.query.filter(app_offers.affiliate_id==AFFILIATE_ID).filter(app_offers.package_name==offer['packageName']).filter(app_offers.show==True).first()
|
| 112 |
if existingAppOffer is None:
|
127 |
if existingAppOffer is None:
|
| 113 |
app_offer.show = True
|
128 |
app_offer.show = True
|
| 114 |
app_offer.offer_active = True
|
- |
|
| 115 |
else:
|
129 |
else:
|
| 116 |
if existingAppOffer.affiliate_offer_id not in ACTIVE_OFFERS:
|
130 |
if existingAppOffer.affiliate_offer_id not in ACTIVE_OFFERS:
|
| 117 |
existingAppOffer.show = False
|
131 |
existingAppOffer.show = False
|
| 118 |
app_offer.show = True
|
132 |
app_offer.show = True
|
| 119 |
app_offer.offer_active = True
|
- |
|
| 120 |
else:
|
133 |
else:
|
| 121 |
if existingAppOffer.offer_price <= float(offer['offerPrice']):
|
134 |
if existingAppOffer.offer_price <= float(offer['offerPrice']):
|
| 122 |
existingAppOffer.show = False
|
135 |
existingAppOffer.show = False
|
| 123 |
app_offer.show = True
|
136 |
app_offer.show = True
|
| 124 |
app_offer.offer_active = True
|
- |
|
| 125 |
else:
|
137 |
else:
|
| 126 |
existingAppOffer.show = True
|
138 |
existingAppOffer.show = True
|
| 127 |
existingAppOffer.offer_active = True
|
139 |
existingAppOffer.offer_active = True
|
| 128 |
app_offer.show = False
|
140 |
app_offer.show = False
|
| 129 |
|
141 |
|