aurweb/aurweb/scripts/tuvotereminder.py
Kevin Morris 7f6c23d4cb
housekeep: centralize datetime generation
Signed-off-by: Kevin Morris <kevr@0cost.org>
2022-01-18 07:31:04 -08:00

35 lines
770 B
Python
Executable file

#!/usr/bin/env python3
from sqlalchemy import and_
import aurweb.config
from aurweb import db, time
from aurweb.models import TUVoteInfo
from aurweb.scripts import notify
notify_cmd = aurweb.config.get('notifications', 'notify-cmd')
def main():
db.get_engine()
now = time.utcnow()
start = aurweb.config.getint("tuvotereminder", "range_start")
filter_from = now + start
end = aurweb.config.getint("tuvotereminder", "range_end")
filter_to = now + end
query = db.query(TUVoteInfo.ID).filter(
and_(TUVoteInfo.End >= filter_from,
TUVoteInfo.End <= filter_to)
)
for voteinfo in query:
notif = notify.TUVoteReminderNotification(voteinfo.ID)
notif.send()
if __name__ == '__main__':
main()