def welcome(company_info): note_name = 'welcome' new_jobs = company_info.jobs_collection.find({'notifications.' + note_name +'.sent': {'$exists' : False }, 'phases.start':{'$gte':datetime.now()}}) msg = get_message_template('welcome') for job in new_jobs: text = msgT.replace_msg_content(msg['message'], {'_name_':job['name'].split()[0], '_company_': company_info.name}) # TODO: generalize company name if company_info.send_sms_to(job, text, note_name): update_job_note_and_message_by_id(company_info, job, note_name, text)
def day_before_confirmation_request(company_info): tomorrow, tomorrow_eod = get_date_start_end(date.today() + timedelta(days=1)) tomorrow_jobs = company_info.jobs_collection.find({'phases.start': {'$gte':tomorrow, '$lte': tomorrow_eod}}) msg = get_message_template('day_before_confirmation_request') for job in tomorrow_jobs: for phase in job['phases']: note_name = phase['name'].lower() + '_day_before_confirmation_request' if tomorrow <= phase['start'] <= tomorrow_eod and not job['notifications'].get(note_name, {}).get('sent', None): #note_name not in job['notifications']: # note: multiple phases in same day make multiple sms'es text = msgT.replace_msg_content(msg['message'], {'_name_':job['name'].split()[0], '_time_':utils.get_arrival_time(phase)}) if company_info.send_sms_to(job, text, note_name): update_job_note_and_message_by_id(company_info, job, note_name, text)
def morning_phase_notification(company_info): today, tomorrow = get_date_start_end(date.today()) today_jobs = company_info.jobs_collection.find({'phases.start': {'$gte':today, '$lte':tomorrow}}) msg = get_message_template('morning_phase_notification') for job in today_jobs: for phase in job['phases']: note_name = phase['name'].lower() + '_morning_phase_notification' if today <= phase['start'] <= tomorrow and not job['notifications'].get('morning_phase_notification', {}).get('sent', None): #note_name not in job['notifications']: # note: multiple phases in same day make multiple sms'es text = msgT.replace_msg_content(msg['message'], {'_name_':job['name'].split()[0], '_time_':phase['start'].strftime('%H:%M')+"-"+phase['end'].strftime('%H:%M')}) if company_info.send_sms_to(job, text, note_name): update_job_note_and_message_by_id(company_info, job, note_name, text)