Пример #1
0
 def test_add_job(self):
     job: IncartJob = IncartJob()
     job.id = '3'
     job.snippet = 'job_3'
     repo = Repo(dal.session)
     ok: bool = repo.add_incartjob(job)
     self.assertTrue(ok)
Пример #2
0
def check_new_email():
    log_info(f"run: check_new_email, new email every {check_new_email_interval} sec.")
    srv = get_service()
    new_messages = get_all_unread_emails(srv)
    count = len(new_messages)
    if count > 0:
        log_info(f"run: check_new_email, has {count} new email(s)")
        with dal.session_scope() as session:
            repo = Repo(session)
            for message in new_messages:
                dct = parse_mail_message(message)
                job = IncartJob.from_json(dct)
                ok: bool = repo.add_incartjob(job)
                if ok:
                    log_info(f"job added to db {job}")
                    jobid_queue.put(job.id)
                    # mark e-mail message as readed
                    labels = {"removeLabelIds":  ['UNREAD'], "addLabelIds": []}
                    modify_message(srv, "me", message["id"], labels)