def getActiveStudents(campaignID): # print "ACTIVE Students" connection = Connection(DB.getDBHost(), DB.getDBPort()) # print "Connecting to Students" try: db = connection.meteor print "Connected to Students" activeStudentList = [] print "Active Student List for Campaign " + campaignID for students in db.students.find({'campaign':campaignID}): # print students['cell'] + " " + students['campaign'] # print " IS Active" activeStudentList.append(students['cell']) connection.close() # print "ACTIVE Students List EXIT" return activeStudentList except: print "GET ACTIVE STUDENT EXCEPTION"
def getCampaignWordsPerDay(campaignID): # print "Get Campaign Words Per Day" connection = Connection(DB.getDBHost(), DB.getDBPort()) try: db = connection.meteor campaign = db.campaigns.find_one({"_id":campaignID}) connection.close() if (campaign == ""): return "1" wordsPerDay = campaign['sendcount'] if (wordsPerDay == ""): return "1" return wordsPerDay except: print "**** getCampaignWordsPerDay Exception ****" return "1"
def getCampaignName(campaignID): # print "Get Campaign Name" connection = Connection(DB.getDBHost(), DB.getDBPort()) try: db = connection.meteor campaign = db.campaigns.find_one({"_id":campaignID}) connection.close() if (campaign == ""): return "N/A" name = campaign['campaign'] if (name == ""): return "N/A" return name except: print "**** getCampaignName Exception ****" return "N/A"
def getActiveWordList(campaignID): print "ACTIVE Word List Order" connection = Connection(DB.getDBHost(), DB.getDBPort()) # print "Connecting to Campaigns" db = connection.meteor # print "Connected to Words" activeWordList = [] # print "Active Word List Order" campaign = db.campaigns.find_one({"_id":campaignID}) connection.close() if (campaign == ""): return "" wordOrder = campaign['cwordorder'] if (wordOrder == ""): return "" wordOrderArray = wordOrder.split(",") for word in wordOrderArray: if (len(word) > 0): activeWordList.append(word) # print "activeWordList add- > " + word return activeWordList
def studentGetRecord(thisCellNumber): connection = Connection(DB.getDBHost(), DB.getDBPort()) db = connection.meteor print "Connected to Students (for Get Record)" collection = db.students try: student = db.students.find_one({'cell':thisCellNumber}) if (student): connection.close() return student except Exception, e: print "Student Get Record EXCEPTION -- %s" % e return ""
def getActiveCampaigns(): print "GET ACTIVE CAMPAIGN" today = datetime.date.today() dayNumber = today.weekday() print "Today is day number " + str(dayNumber) connection = Connection(DB.getDBHost(), DB.getDBPort()) # print "Connecting to Campaign" db = connection.meteor # print "Connected to Campaign" collection = db.campaigns activeCampaignList = [] print "Campaign List" for camp in db.campaigns.find().sort("campaign", pymongo.ASCENDING): # print "Campaign Loop " + camp['campaign'] # print "Campaign Exclude Dates " + camp['xdatelist'] try: if ((camp['campaign'], camp['xdatelist']) == True): print "Campaign Excluded Today - " + camp['campaign'] continue # print "Campaign Not Excluded Today - " + camp['campaign'] if activeToday(camp, dayNumber): print "Campaign Active Today - " + camp['campaign'] activeCampaignList.append(camp['_id']) # else: # print "Campaign Not Active Today - " + camp['campaign'] except Exception, e: print "getActiveCampaigns EXCEPTION -- %s" % e print "Exception in calling activeToday()" print "Campaign " + camp['campaign']
def studentAddLogLine(thisCellNumber, logLine): connection = Connection(DB.getDBHost(), DB.getDBPort()) db = connection.meteor print "Connected to Students (for status log)" try: student = db.students.find_one({'cell':thisCellNumber}) if (student): thisLine = student['studentStatus'] + "\r\n" + logLine student['studentStatus'] = thisLine db.students.update({'_id': student['_id']}, {'cell': student['cell'], 'name': student['name'], 'login':student['login'], 'pword':student['pword'], 'tzoffset': student['tzoffset'], 'allowaudio':student['allowaudio'], 'campaign':student['campaign'], 'studentStatus': thisLine}) connection.close() return except Exception, e: print "Student Add Log Line EXCEPTION -- %s" % str(e)