-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_functions.py
More file actions
76 lines (58 loc) · 1.72 KB
/
file_functions.py
File metadata and controls
76 lines (58 loc) · 1.72 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from pip._vendor import requests
import json
import re
to_do_list = []
completed_tasks = []
def open_task_lists():
"""
Open txt files to load To-Do List Tasks and
Completed Tasks saved from previous session
"""
open_tasks()
open_completed_tasks()
def open_tasks():
task_list = open('tasks.txt', 'r')
tasks = task_list.readlines()
for task in tasks:
to_do_list.append(json.loads(task))
update_due_messages()
task_list.close()
def update_due_messages():
for task in to_do_list:
due_message = get_message(task['Due'])
task['Msg'] = due_message
def open_completed_tasks():
task_list = open('completed_tasks.txt', 'r')
tasks = task_list.readlines()
for task in tasks:
completed_tasks.append(json.loads(task))
task_list.close()
def save_task_lists():
"""
Write to txt files to save To-Do List Tasks and
Completed Tasks for next session
"""
save_tasks()
save_completed_tasks()
def save_tasks():
task_list = open('tasks.txt', 'w')
for task in to_do_list:
task_list.writelines([json.dumps(task), '\n'])
task_list.close()
def save_completed_tasks():
task_list = open('completed_tasks.txt', 'w')
for task in completed_tasks:
task_list.writelines([json.dumps(task), '\n'])
task_list.close()
def get_message(date):
"""
Call to partner's microservice that sends a date and receives a
message string that tells user when each task is due
"""
url = f"http://localhost:8081/due/{date}"
response = requests.get(url)
json_data = json.loads(response.text)
message = json_data['message']
if re.search('ago', message):
message += " [OVERDUE!]"
return message