| Line 171... |
Line 171... |
| 171 |
user_records = cursor.fetchall()
|
171 |
user_records = cursor.fetchall()
|
| 172 |
userids = []
|
172 |
userids = []
|
| 173 |
for record in user_records:
|
173 |
for record in user_records:
|
| 174 |
if record[0] not in userids:
|
174 |
if record[0] not in userids:
|
| 175 |
userids.append(str(record[0]))
|
175 |
userids.append(str(record[0]))
|
| 176 |
campaignUsersMap[campaign['_id']]=userids
|
176 |
campaignUsersMap[str(campaign['_id'])]=userids
|
| 177 |
notificationCampaignsMap[campaign['_id']] = campaign
|
177 |
notificationCampaignsMap[str(campaign['_id'])] = campaign
|
| 178 |
|
178 |
|
| 179 |
def insertPushNotificationEntriesToSent():
|
179 |
def insertPushNotificationEntriesToSent():
|
| 180 |
global userGcmRegIdMap
|
180 |
global userGcmRegIdMap
|
| 181 |
for userList in campaignUsersMap.values():
|
181 |
for userList in campaignUsersMap.values():
|
| 182 |
logging.debug("GCM_REG_SQL_1:- "+GCM_REG_ID_SQL1%(str(tuple(userList))))
|
182 |
logging.debug("GCM_REG_SQL_1:- "+GCM_REG_ID_SQL1%(str(tuple(userList))))
|
| Line 206... |
Line 206... |
| 206 |
if dataRec[3] is not None:
|
206 |
if dataRec[3] is not None:
|
| 207 |
detailMap['android_id'] = dataRec[3]
|
207 |
detailMap['android_id'] = dataRec[3]
|
| 208 |
gcmRegIdMap[dataRec[2]]= detailMap
|
208 |
gcmRegIdMap[dataRec[2]]= detailMap
|
| 209 |
userGcmRegIdMap[dataRec[0]] = gcmRegIdMap
|
209 |
userGcmRegIdMap[dataRec[0]] = gcmRegIdMap
|
| 210 |
|
210 |
|
| 211 |
logging.debug("Old Users.."+str(user_list))
|
211 |
logging.debug("Old Users.."+str(user_list))
|
| - |
|
212 |
if len(user_list)<=1:
|
| - |
|
213 |
user_list.append('0')
|
| - |
|
214 |
user_list.append('0')
|
| 212 |
logging.debug("GCM_REG_SQL_2:- "+GCM_REG_ID_SQL2%(str(tuple(user_list))))
|
215 |
logging.debug("GCM_REG_SQL_2:- "+GCM_REG_ID_SQL2%(str(tuple(user_list))))
|
| 213 |
cursor.execute(GCM_REG_ID_SQL2%(str(tuple(user_list))))
|
216 |
cursor.execute(GCM_REG_ID_SQL2%(str(tuple(user_list))))
|
| 214 |
result_data = cursor.fetchall()
|
217 |
result_data = cursor.fetchall()
|
| 215 |
for dataRec in result_data:
|
218 |
for dataRec in result_data:
|
| 216 |
if userGcmRegIdMap.has_key(dataRec[0]):
|
219 |
if userGcmRegIdMap.has_key(dataRec[0]):
|
| Line 261... |
Line 264... |
| 261 |
for gcm_id, details in gcmRegIdMap.items():
|
264 |
for gcm_id, details in gcmRegIdMap.items():
|
| 262 |
android_id = None
|
265 |
android_id = None
|
| 263 |
logging.debug("User Id:- "+str(userId)+" ..User Details:- "+str(details))
|
266 |
logging.debug("User Id:- "+str(userId)+" ..User Details:- "+str(details))
|
| 264 |
if details.has_key('android_id'):
|
267 |
if details.has_key('android_id'):
|
| 265 |
android_id = details['android_id']
|
268 |
android_id = details['android_id']
|
| 266 |
pushNotificationObj = __PushNotification(campaignId, userId, None, 'pending', \
|
269 |
pushNotificationObj = __PushNotification(str(campaignId), userId, None, 'pending', \
|
| 267 |
None, None, android_id, "php", None, None, None, None, gcm_id, to_java_date(datetime.now()),0)
|
270 |
None, None, android_id, "php", None, None, None, None, gcm_id, to_java_date(datetime.now()),0)
|
| 268 |
get_mongo_connection(host=mongoHost).User.pushnotifications.insert(pushNotificationObj.__dict__)
|
271 |
get_mongo_connection(host=mongoHost).User.pushnotifications.insert(pushNotificationObj.__dict__)
|
| 269 |
|
272 |
|
| 270 |
def populatePendingNotificationEntriesToBeSent():
|
273 |
def populatePendingNotificationEntriesToBeSent():
|
| 271 |
global pendingNotificationEntryMap
|
274 |
global pendingNotificationEntryMap
|
| Line 292... |
Line 295... |
| 292 |
count = count +1
|
295 |
count = count +1
|
| 293 |
logging.debug('Stopping Push Notification Job....'+str(datetime.now()))
|
296 |
logging.debug('Stopping Push Notification Job....'+str(datetime.now()))
|
| 294 |
|
297 |
|
| 295 |
def markNotificationCampaignsProcessed():
|
298 |
def markNotificationCampaignsProcessed():
|
| 296 |
for campaign in notificationCampaignsMap.values():
|
299 |
for campaign in notificationCampaignsMap.values():
|
| 297 |
logging.debug('Notification Campaign....'+str(campaign.get('notification_id'))+"...Marked Processed. "+str(datetime.now()))
|
300 |
logging.debug('Notification Campaign....'+str(campaign.get('_id'))+"...Marked Processed. "+str(datetime.now()))
|
| 298 |
get_mongo_connection(host=mongoHost).User.notificationcampaigns.update({'_id':campaign.get('_id')},{"$set":{'notification_processed':1}})
|
301 |
get_mongo_connection(host=mongoHost).User.notificationcampaigns.update({'_id':campaign.get('_id')},{"$set":{'notification_processed':1}})
|
| 299 |
|
302 |
|
| 300 |
def main():
|
303 |
def main():
|
| 301 |
global mongoHost
|
304 |
global mongoHost
|
| 302 |
parser = optparse.OptionParser()
|
305 |
parser = optparse.OptionParser()
|