-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.py
62 lines (47 loc) · 1.33 KB
/
functions.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from time import strftime
import os
import sys
if not os.path.exists('todos.txt'):
with open('todos.txt', 'w') as file:
pass
FILEPATH = 'todos.txt'
def get_todos():
"""
Creates list based on previous todos
:return:
"""
with open(FILEPATH, 'r') as todos_file:
todo_list = todos_file.readlines()
return todo_list
def update_file(todos):
"""
Updates todos.txt file with new values of todo_list.
:param todos: list of to-dos
"""
with open(FILEPATH, 'w') as todos_file_f:
todos_file_f.writelines(todos)
def index_from_todo(index_input):
"""
Picks the index of the to-do to be edited/completed by the user.
:param index_input: index given from the user
:returns: the given index minus 1
"""
todo_index = int(index_input)
todo_index -= 1
return todo_index
def get_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
def get_time():
"""
Gets time and formats into string.
"""
n = strftime('%A, %b %d, %Y %H:%M:%S')
return n
if __name__ == '__main__':
pass