-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
38 lines (28 loc) · 1.07 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
import slack
from config import filepath_config
from datetime import date, timedelta
SETTINGS = filepath_config()
PATH = SETTINGS['filepath']
def get_keycode(today):
new_code = old_code = None
with open(PATH) as keyfile:
for key in keyfile:
date, recipient, sender, subject, code = key.split('|')
if date.strip() == str(today):
code = code.split(';')
new_code = ''.join(filter(str.isdigit, code[0]))
old_code = ''.join(filter(str.isdigit, code[1]))
return new_code, old_code
next_post = today = date.today()
if next_post != today:
slack.post_message("#keys", "There shall be no post today!")
exit()
new_code, old_code = get_keycode(today)
if new_code is None or old_code is None:
new_code, old_code = get_keycode(today-timedelta(today.isoweekday()))
slack.post_message(
"#keys", f"No keys for today the new code is: {new_code}")
exit()
slack.post_message(
"#keys", f"Havne keys has been updated: \n {old_code} -> {new_code}")
next_post += timedelta(days=7)