From ab5c6e771287cfbeeabc41be0b81e096f999eb45 Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Sat, 1 Apr 2023 10:44:37 -0700 Subject: [PATCH] Add http_get notification type and toggle for read_only mailbox This closes #2 --- clacksme/clacksme.py | 10 +++++++++- clacksme/model.py | 30 +++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/clacksme/clacksme.py b/clacksme/clacksme.py index 3977afb..3ec7efe 100644 --- a/clacksme/clacksme.py +++ b/clacksme/clacksme.py @@ -36,7 +36,8 @@ class MailboxNotifier(object): with IMAPClient(self.mailbox.imap_host) as self.imap: self.imap.login(self.mailbox.imap_user, self.mailbox.imap_pass) - self.imap.select_folder("INBOX", readonly=True) + self.imap.select_folder("INBOX", + readonly=self.mailbox.read_only) self.log.info("Connected to INBOX") messages = self.imap.search("UNSEEN") if len(messages) > 0: @@ -114,6 +115,9 @@ class MailboxNotifier(object): if target.service == "mattermost" and target.enabled: self.send_mattermost(target.target, text) + if target.service == "http_get" and target.enabled: + self.send_http_get(target.target) + def send_pushover(self, po_user, text): notifier = Notifier.get(Notifier.service == "pushover") url = "https://api.pushover.net/1/messages.json" @@ -134,6 +138,10 @@ class MailboxNotifier(object): self.log.debug(response.status_code) self.log.debug(response.text) + def send_http_get(self, url): + response = requests.get(url) + self.log.debug(response.status_code) + self.log.debug(response.text) def shutdown_handler(signal, frame): _shtudown.set() diff --git a/clacksme/model.py b/clacksme/model.py index a26593c..fd8d48b 100644 --- a/clacksme/model.py +++ b/clacksme/model.py @@ -5,7 +5,7 @@ from playhouse.sqlite_ext import SqliteExtDatabase db = SqliteExtDatabase(None) migrator = SqliteMigrator(db) -db_schema = "1" +db_schema = "2" class BaseModel(Model): class Meta: @@ -21,6 +21,7 @@ class Mailbox(BaseModel): imap_user = CharField() imap_pass = CharField() last_check = DateTimeField(null=True) + read_only = BooleanField(default=True) class Events(BaseModel): user = CharField() @@ -44,3 +45,30 @@ def create_tables(): with db: if not db.table_exists(System._meta.table_name): db.create_tables(tables) + System.replace(key="schema", value=db_schema).execute() + + else: + schema_ver = System.get_or_none(key="schema") + migrate_tables(schema_ver) + +def migrate_tables(schema_ver): + if schema_ver is None or schema_ver.value == "1": + schema_ver = migrate_v2() + + # if schema_ver == "2": + # schema_ver = migrate_v3() + + System.replace(key="schema", value=db_schema).execute() + +def migrate_v2(): + # migration to schema version 2 + read_only = BooleanField(default=True) + migrate( + migrator.add_column( + Mailbox._meta.table_name, 'read_only', read_only), + ) + return "2" + +# def migrate_v3(): +# # migration to schema version 3 +# return "3"