from .models import database, Repeat, SkipDay, OrderStatus, PunishmentStatus def initdb(): database.connect() database.create_tables([ Repeat, SkipDay, OrderStatus, PunishmentStatus ]) def repeat_get(): try: return Repeat.get() except Repeat.DoesNotExist: return None def repeat_increment(): q = Repeat.update(count=Repeat.count + 1) return q.execute() def repeat_put(probability, orders): return Repeat.create( probability=probability, orders=orders ) def repeat_clear(): q = Repeat.delete() q.execute() def skip_day_put(date): return SkipDay.create(date=date) def skip_day_contains(date): q = SkipDay.select().where(SkipDay.date == date) return len(q) > 0 def order_status_put(mastodon_id, created_at, due_at, text): return OrderStatus.create( mastodon_id=mastodon_id, created_at=created_at, due_at=due_at, text=text ) def order_status_outstanding(): return OrderStatus.select().where( (OrderStatus.confirmed_at.is_null()) & (OrderStatus.punishment_id.is_null()) ) def order_status_confirm(id, confirmed_at): q = OrderStatus.update( confirmed_at=confirmed_at ).where( OrderStatus.id == id ) return q.execute() def punishment_status_put(order_status_id, mastodon_id, created_at, text): punishment_status = PunishmentStatus.create( mastodon_id=mastodon_id, created_at=created_at, text=text ) q = OrderStatus.update( punishment_id=punishment_status.id ).where( OrderStatus.id == order_status_id ) q.execute()