This repository has been archived by the owner on Dec 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
47 lines (31 loc) · 1.68 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from models import session, Reminder
import time
import requests
from datetime import datetime
import configparser
config = configparser.SafeConfigParser()
config.read('config.ini')
while True:
rems = []
for reminder in session.query(Reminder).filter(Reminder.time <= time.time()).filter(Reminder.webhook != ''):
url = reminder.webhook
rems.append(reminder.id)
print('Looping for reminder {}'.format(reminder))
if reminder.interval is not None and reminder.interval < 8:
continue
try:
if reminder.interval is None:
requests.post(url, {'content': reminder.message, 'username': 'Reminders', 'avatar_url': 'https://raw.githubusercontent.com/reminder-bot/logos/master/Remind_Me_Bot_Logo_PPic.jpg'})
print('{}: Administered reminder to {}'.format(datetime.utcnow().strftime('%H:%M:%S'), reminder.webhook))
else:
rems.remove(reminder.id)
requests.post(url, {'content': reminder.message, 'username': 'Reminders', 'avatar_url': 'https://raw.githubusercontent.com/reminder-bot/logos/master/Remind_Me_Bot_Logo_PPic.jpg'})
print('{}: Administered interval to {} (Reset for {} seconds)'.format(datetime.utcnow().strftime('%H:%M:%S'), reminder.webhook, reminder.interval))
while reminder.time <= time.time():
reminder.time += reminder.interval ## change the time for the next interval
except Exception as e:
print('Ln 1033: {}'.format(e))
if len(rems) > 0:
session.query(Reminder).filter(Reminder.id.in_(rems)).delete(synchronize_session='fetch')
time.sleep(2.5)
session.commit()