From cef4a1b7313fe0b266fe7753f244b93a13975405 Mon Sep 17 00:00:00 2001 From: Johnny Gear Date: Thu, 13 Nov 2025 22:03:20 -0600 Subject: [PATCH] Scheduling - skip days --- db.py | 36 +++++++++++++++++++++++++++--------- main.py | 1 - mastodon.py | 1 - scheduling.py | 11 +++++++++++ 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/db.py b/db.py index dcf2aad..f8e6c07 100644 --- a/db.py +++ b/db.py @@ -1,11 +1,9 @@ -import os import sqlite3 -import datetime from settings import SQLITE_DB -TABLE_REPEATS = ''' - CREATE TABLE IF NOT EXISTS repeats ( +TABLE_REPEAT = ''' + CREATE TABLE IF NOT EXISTS repeat ( id INTEGER PRIMARY KEY AUTOINCREMENT, probability FLOAT NOT NULL, orders TEXT NOT NULL, @@ -13,6 +11,13 @@ TABLE_REPEATS = ''' ); ''' +TABLE_SKIP_DAY = ''' + CREATE TABLE IF NOT EXISTS skip_day ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + date TIMESTAMP UNIQUE NOT NULL + ); +''' + TABLE_ORDER_STATUS = ''' CREATE TABLE IF NOT EXISTS order_status ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -39,7 +44,8 @@ class Database: def __init__(self): self.conn = sqlite3.connect(SQLITE_DB) self.conn.row_factory = sqlite3.Row - self.table_init(TABLE_REPEATS) + self.table_init(TABLE_REPEAT) + self.table_init(TABLE_SKIP_DAY) self.table_init(TABLE_PUNISHMENT_STATUS) self.table_init(TABLE_ORDER_STATUS) @@ -56,21 +62,33 @@ class Database: def repeat_get(self): c = self.conn.cursor() - sql = 'SELECT id, probability, orders, count FROM repeats LIMIT 1' + sql = 'SELECT id, probability, orders, count FROM repeat LIMIT 1' c.execute(sql) return c.fetchone() def repeat_increment(self): - self.update('UPDATE repeats SET count = count + 1') + self.update('UPDATE repeat SET count = count + 1') def repeat_put(self, probability, orders): self.update( - 'INSERT INTO repeats (probability, orders) VALUES (?, ?);', + 'INSERT INTO repeat (probability, orders) VALUES (?, ?);', [probability, orders] ) def repeat_clear(self): - self.update('DELETE FROM repeats') + self.update('DELETE FROM repeat') + + def skip_day_put(self, date): + self.update( + 'INSERT INTO skip_day (date) VALUES (?);', + [date] + ) + + def skip_day_contains(self, date): + c = self.conn.cursor() + sql = 'SELECT * FROM skip_day WHERE date=?;' + c.execute(sql, [date]) + return c.fetchone() is not None def order_status_put(self, mastodon_id, created_at, text): self.update( diff --git a/main.py b/main.py index 43824b8..51ac8ca 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,3 @@ -import os import sys import logging import argparse diff --git a/mastodon.py b/mastodon.py index 6558253..6d30abc 100644 --- a/mastodon.py +++ b/mastodon.py @@ -1,4 +1,3 @@ -import os import logging from settings import MASTODON_INSTANCE, MASTODON_ACCESS_TOKEN diff --git a/scheduling.py b/scheduling.py index ddb2e97..948d236 100644 --- a/scheduling.py +++ b/scheduling.py @@ -6,6 +6,7 @@ from scheduler.asyncio import Scheduler from settings import TIMEZONE, ORDER_TIME, ORDER_TIMEOUT from orders import order_issue, order_check +from db import Database logger = logging.getLogger(__name__) @@ -25,8 +26,18 @@ class OrderScheduler(): logger.info(self.scheduler) async def scheduled_order(self): + # Skip weekends day_of_week = datetime.datetime.now(tz=self.tz).weekday() if (day_of_week in [SATURDAY, SUNDAY]): + logger.info('Today is a weekend') + return + + # Skip stored dates + d = Database() + today = datetime.datetime.now(tz=self.tz).strftime("%Y-%d-%m") + logger.info('Today %s' % today) + if (d.skip_day_contains(today)): + logger.info('Today is a skip day') return await order_issue()