-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
77 lines (57 loc) · 2.42 KB
/
utils.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import os
import datetime
from prettytable import PrettyTable
from layout import import_commands
MAIN_DIR = "./docs/"
FORMAT = ".txt"
TABLE_FORMAT = ".html"
DATE_PATTERN = "%B %d %Y - %I:%M %p"
def dir_check(path):
if not os.path.exists(path):
os.mkdir(path)
def init_file():
year_dir = datetime.datetime.now().strftime("%Y") + "/"
month_dir = datetime.datetime.now().strftime("%m") + "/"
name = datetime.datetime.now().strftime("%d") + "/"
dir_check(MAIN_DIR)
dir_check(MAIN_DIR + year_dir)
dir_check(MAIN_DIR + year_dir + month_dir)
dir_check(MAIN_DIR + year_dir + month_dir + name)
file_path = MAIN_DIR + year_dir + month_dir + name + "doc" + FORMAT
html_path = MAIN_DIR + year_dir + month_dir + name + "table" + TABLE_FORMAT
with open(file_path, 'w') as file:
file.write(f'> {datetime.datetime.now().strftime(DATE_PATTERN)}\n\n')
with open(html_path, 'w') as file:
file.write(f'<h2>{datetime.datetime.now().strftime(DATE_PATTERN)}</h2>')
def save_to_now(string):
year_dir = datetime.datetime.now().strftime("%Y") + "/"
month_dir = datetime.datetime.now().strftime("%m") + "/"
name = datetime.datetime.now().strftime("%d") + "/"
file_path = MAIN_DIR + year_dir + month_dir + name + "doc" + FORMAT
with open(file_path, 'a+') as file:
file.write(string)
def save_to_html(title, dictionary):
year_dir = datetime.datetime.now().strftime("%Y") + "/"
month_dir = datetime.datetime.now().strftime("%m") + "/"
name = datetime.datetime.now().strftime("%d") + "/"
file_path = MAIN_DIR + year_dir + month_dir + name + "table" + TABLE_FORMAT
x = PrettyTable(["Rank", "Team name", "Game play", "Win",
"Draw", "Lose", "Points"])
for index in dictionary.keys():
dictionary[index].insert(0, index)
x.add_row(dictionary[index])
with open(file_path,'a+') as file:
file.write(x.get_html_string(title=title))
def write_in_html(string):
year_dir = datetime.datetime.now().strftime("%Y") + "/"
month_dir = datetime.datetime.now().strftime("%m") + "/"
name = datetime.datetime.now().strftime("%d") + "/"
file_path = MAIN_DIR + year_dir + month_dir + name + "table" + TABLE_FORMAT
with open(file_path,'a+') as file:
file.write(string)
def layout_import():
year_dir = datetime.datetime.now().strftime("%Y") + "/"
month_dir = datetime.datetime.now().strftime("%m") + "/"
name = datetime.datetime.now().strftime("%d") + "/"
file_path = MAIN_DIR + year_dir + month_dir + name + "table" + TABLE_FORMAT
import_commands(file_path)