| Line 58... |
Line 58... |
| 58 |
'SkuSchemeDetails':'skuBundleId',
|
58 |
'SkuSchemeDetails':'skuBundleId',
|
| 59 |
'DealPoints':'skuBundleId',
|
59 |
'DealPoints':'skuBundleId',
|
| 60 |
'FeaturedDeals': 'skuBundleId'
|
60 |
'FeaturedDeals': 'skuBundleId'
|
| 61 |
}
|
61 |
}
|
| 62 |
|
62 |
|
| - |
|
63 |
class __NotificationCampaign:
|
| - |
|
64 |
def __init__(self, campaignId, name, title, message, sql, url, created, expiresat, type, status, sendsms, messagetext, smsprocessed, notification_processed, notification_type):
|
| - |
|
65 |
self._id = campaignId
|
| - |
|
66 |
self.name = name
|
| - |
|
67 |
self.title = title
|
| - |
|
68 |
self.message = message
|
| - |
|
69 |
self.sql = sql
|
| - |
|
70 |
self.url = url
|
| - |
|
71 |
self.created = created
|
| - |
|
72 |
self.expiresat = expiresat
|
| - |
|
73 |
self.type = type
|
| - |
|
74 |
self.status = status
|
| - |
|
75 |
self.sendsms = sendsms
|
| - |
|
76 |
self.messagetext = messagetext
|
| - |
|
77 |
self.smsprocessed = smsprocessed
|
| - |
|
78 |
self.notification_processed = notification_processed
|
| - |
|
79 |
self.notification_type = notification_type
|
| - |
|
80 |
self.notification_long_text = None
|
| - |
|
81 |
|
| 63 |
def get_elastic_search_connection():
|
82 |
def get_elastic_search_connection():
|
| 64 |
global es
|
83 |
global es
|
| 65 |
if es is None:
|
84 |
if es is None:
|
| 66 |
print "Establishing connection with elastic search %s host and port %s"%(elastic_search_host,elastic_search_port)
|
85 |
print "Establishing connection with elastic search %s host and port %s"%(elastic_search_host,elastic_search_port)
|
| 67 |
es = Elasticsearch([{'host': elastic_search_host, 'port': elastic_search_port}])
|
86 |
es = Elasticsearch([{'host': elastic_search_host, 'port': elastic_search_port}])
|
| Line 2233... |
Line 2252... |
| 2233 |
mc.set("cached_app_offers_"+str(retailerId), finalAppOffersMap, 120)
|
2252 |
mc.set("cached_app_offers_"+str(retailerId), finalAppOffersMap, 120)
|
| 2234 |
else:
|
2253 |
else:
|
| 2235 |
print 'No Offers'
|
2254 |
print 'No Offers'
|
| 2236 |
mc.set("cached_app_offers_"+str(retailerId), {}, 10)
|
2255 |
mc.set("cached_app_offers_"+str(retailerId), {}, 10)
|
| 2237 |
|
2256 |
|
| 2238 |
def sendNotification(userIds, campaignName, title, message,notificationtype, url, expiresat='2999-01-01', sendsms=False, smstext=None):
|
2257 |
def sendNotification(userIds, campaignName, title, message,notificationtype, url, expiresat='2999-01-01', sendsms=False, smstext=None, mongoHost='localhost'):
|
| 2239 |
campaignId = addNotificationCampaign(campaignName, title, message, notificationtype, url, None, sendsms, smstext)
|
2258 |
max_id = list(get_mongo_connection(host=mongoHost).User.notificationcampaigns.find().sort([('_id',pymongo.DESCENDING)]).limit(1))
|
| 2240 |
payload = {}
|
2259 |
if len(max_id) ==0:
|
| 2241 |
payload["user_id"]= userIds[0]
|
- |
|
| 2242 |
payload["type"]="pending"
|
- |
|
| 2243 |
payload["notification_campaign_id"]= campaignId
|
- |
|
| 2244 |
payload["status"]=0
|
- |
|
| 2245 |
|
- |
|
| 2246 |
payloadList = []
|
2260 |
max_id = 0
|
| 2247 |
payloadList.append(payload)
|
- |
|
| 2248 |
jsonObj = json.dumps([dict(pn) for pn in payloadList])
|
- |
|
| 2249 |
print jsonObj
|
- |
|
| 2250 |
pushpostrequest = urllib2.Request("http://45.33.50.227:3001/addPushNotification")
|
- |
|
| 2251 |
pushpostrequest.add_header('Content-Type', 'application/json')
|
- |
|
| 2252 |
response = urllib2.urlopen(pushpostrequest, jsonObj).read()
|
- |
|
| 2253 |
print response
|
- |
|
| 2254 |
|
2261 |
else:
|
| 2255 |
def addNotificationCampaign(name, title, message, type, url, sql, sendsms, smstext):
|
- |
|
| 2256 |
notificationCampaign = notification_campaigns()
|
- |
|
| 2257 |
notificationCampaign.name = name
|
- |
|
| 2258 |
notificationCampaign.title = title
|
2262 |
max_id = max_id[0]['_id']
|
| 2259 |
notificationCampaign.type = type
|
- |
|
| 2260 |
notificationCampaign.message = message
|
- |
|
| 2261 |
notificationCampaign.url = url
|
- |
|
| 2262 |
notificationCampaign.sql = sql
|
2263 |
max_id = max_id +1
|
| 2263 |
notificationCampaign.expiresat = datetime(2999, 1, 1)
|
- |
|
| 2264 |
notificationCampaign.status = 'active'
|
2264 |
campaign = __NotificationCampaign(max_id, campaignName, title, message, "SELECT User.id from users User where User.id="+str(userIds[0]), url, to_java_date(datetime.now()), to_java_date(datetime.now()+timedelta(year=500)), notificationtype, 'active', sendsms, smstext, 0, 0, 'BATCH_CREDIT')
|
| 2265 |
notificationCampaign.created = datetime.now()
|
2265 |
get_mongo_connection(host=mongoHost).User.notificationcampaigns.insert(campaign.__dict__)
|
| 2266 |
notificationCampaign.sendsms = sendsms
|
- |
|
| 2267 |
notificationCampaign.messagetext = smstext
|
- |
|
| 2268 |
|
- |
|
| 2269 |
session.commit()
|
- |
|
| 2270 |
campaignId = notificationCampaign.id
|
- |
|
| 2271 |
|
- |
|
| 2272 |
session.close()
|
- |
|
| 2273 |
return campaignId
|
- |
|
| 2274 |
|
2266 |
|
| 2275 |
def getDummyDeals(categoryId, offset, limit):
|
2267 |
def getDummyDeals(categoryId, offset, limit):
|
| 2276 |
outer_query = []
|
2268 |
outer_query = []
|
| 2277 |
outer_query.append({"showDeal":1})
|
2269 |
outer_query.append({"showDeal":1})
|
| 2278 |
outer_query.append({"category_id":categoryId})
|
2270 |
outer_query.append({"category_id":categoryId})
|