def receive(self, mail_message):
     sender = mail_message.sender
     html_body = None
     plain_body = None
     for content_type, body in mail_message.bodies("text/plain"):
         plain_body = body.decode()
     for content_type, body in mail_message.bodies("text/html"):
         html_body = body.decode()
     message_date = mail_message.date
     wu = WeeklyUpdate(sender=sender, plain_body=plain_body, html_body=html_body)
     try:
         wu.put()
     except ValidationError, e:
         logging.warning(e.message)
Exemple #2
0
 def receive(self, mail_message):
     sender = mail_message.sender
     html_body = None
     plain_body = None
     for content_type, body in mail_message.bodies('text/plain'):
         plain_body = body.decode()
     for content_type, body in mail_message.bodies('text/html'):
         html_body = body.decode()
     message_date = mail_message.date
     wu = WeeklyUpdate(
         sender=sender,
         plain_body=plain_body,
         html_body=html_body,
     )
     try:
         wu.put()
     except ValidationError, e:
         logging.warning(e.message)
Exemple #3
0
 def get(self):
     if datetime.date.today().weekday() == REMINDER_DAY:
         logging.info('Reminder scheduled today!')
         email = WeeklyUpdate.generate_reminder_email()
         if email is not None:
             logging.info('Sending')
             email.send()
         else:
             logging.info('Everyone has sent updates! Skipping reminder.')
     else:
         logging.info('No reminder scheduled today.')
def save_to_db(user_id, current_question, ds, body):
    if current_question == 'mood_score':
        try:
            body = int(body)
            assert body <= 5
            assert body >= 1
        except (ValueError, AssertionError):
            return MOOD_SCORE_FAILURE_MESSAGE
        # write to db
        entry = DailyEntry(user_id, ds, body)
        db.session.add(entry)
        db.session.commit()
    elif current_question == 'mood_reason':
        entry = DailyEntry.get_by_userid_and_ds(user_id, ds)
        entry.mood_reason = body
        db.session.add(entry)
        db.session.commit()
    elif current_question == 'daily_updates':
        updates = parse_updates_and_tags(body)
        # get entryid
        entry = DailyEntry.get_by_userid_and_ds(user_id, ds)
        entry_id = entry.id
        # save all updates
        for update in updates:
            update_obj = DailyUpdate(user_id, entry_id, ds, update['update'])
            db.session.add(update_obj)
            # auto populate next ID into update_obj
            db.session.flush()
            for tag in update['tags']:
                tag_obj = DailyTag(user_id, entry_id, update_obj.id, ds, tag)
                db.session.add(tag_obj)
        db.session.commit()
    elif current_question == 'weekly_updates':
        updates = parse_updates_and_tags(body)
        for update in updates:
            update_obj = WeeklyUpdate(user_id, ds, update['update'])
            db.session.add(update_obj)
            # auto populate next ID into update_obj
            db.session.flush()
            for tag in update['tags']:
                tag_obj = WeeklyTag(user_id, update_obj.id, ds, tag)
                db.session.add(tag_obj)
        db.session.commit()
    return None
Exemple #5
0
 def get(self):
     content = WeeklyUpdate.generate_summary_content(WeeklyUpdate.get_weekly_updates())
     email = WeeklyUpdate.generate_summary_email(content)
     email.send()
Exemple #6
0
 def get(self):
     content = WeeklyUpdate.generate_summary_content(WeeklyUpdate.get_weekly_updates())
     email = WeeklyUpdate.generate_summary_email(content)
     self.response.out.write(email.html)