change(tuvotereminder): converted to use aurweb.db ORM

- Removed tuvotereminder sharness test.
- Added [tuvotereminder] section to config.defaults.
- Added `range_start` option to config.defaults [tuvotereminder].
- Added `range_end` option to config.defaults [tuvotereminder].

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-11-22 10:28:58 -08:00
parent 29c2d0de6b
commit 8d5683d3f1
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
4 changed files with 131 additions and 65 deletions

View file

@ -1,27 +1,36 @@
#!/usr/bin/env python3
import subprocess
import time
from datetime import datetime
from sqlalchemy import and_
import aurweb.config
import aurweb.db
from aurweb import db
from aurweb.models import TUVoteInfo
from aurweb.scripts import notify
notify_cmd = aurweb.config.get('notifications', 'notify-cmd')
def main():
conn = aurweb.db.Connection()
db.get_engine()
now = int(time.time())
filter_from = now + 500
filter_to = now + 172800
now = int(datetime.utcnow().timestamp())
cur = conn.execute("SELECT ID FROM TU_VoteInfo " +
"WHERE End >= ? AND End <= ?",
[filter_from, filter_to])
start = aurweb.config.getint("tuvotereminder", "range_start")
filter_from = now + start
for vote_id in [row[0] for row in cur.fetchall()]:
subprocess.Popen((notify_cmd, 'tu-vote-reminder', str(vote_id))).wait()
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__':