-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_days.py
executable file
·33 lines (27 loc) · 1.24 KB
/
find_days.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
"""Find dates to send reminder email."""
from datetime import datetime as dt
from datetime import timedelta as td
from random import randint
from os import path
str_format = '%Y-%m-%d'
file_path = "/home/fake_user/article_reminder/dates.txt"
if __name__ == "__main__":
year, month, _ = dt.today().strftime(str_format).split('-')
current_day = int(dt.today().strftime('%u'))
if path.isfile(file_path):
with open(file_path) as f:
dates = f.readlines()
if len(dates) > 0:
final_date = dt.strptime(dates[-1].rstrip('\n'), str_format)
else:
final_date = dt.strptime('1980-01-01', str_format)
else:
final_date = dt.strptime('1980-01-01', str_format)
if (not path.isfile(file_path)) or ((dt.today() - td(days=int(dt.today().strftime('%u')))) > final_date):
next_email = dt.today() + td(days=randint(0, 7-current_day))
print next_email.strftime(str_format)
next_sunday = dt.today() + td(days=7-current_day)
while (int(next_sunday.strftime('%m')) <= int(month)) and (int(next_sunday.strftime('%Y')) <= int(year)):
try_day = next_sunday + td(days=randint(0,6))
print try_day.strftime(str_format)
next_sunday = next_sunday + td(days=7)