Skip to content

Commit f2c3c07

Browse files
committed
In the "Diary_Slim" module, I made the following changes:
I improved the "Write_On_Diary_Slim_Module" sub-class a lot, organizing it more, and making it prettier. I improved the way the text to be written is defined and modified, removing unnecessary class parameters. And I also made a root dictionary to better organize all the variables, texts, dictionaries, and switches.
1 parent d9cec39 commit f2c3c07

File tree

12 files changed

+211
-82
lines changed

12 files changed

+211
-82
lines changed

Module Files/Food_Time/Times.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"Will be hungry": 3
1111
},
1212
"Ate": {
13-
"Object": "2024-04-02 20:43:06-03:00",
13+
"Object": "2024-04-09 04:39:12-03:00",
1414
"Time": 0,
15-
"Time text": "20:43",
15+
"Time text": "04:39",
1616
"Unit": {
1717
"en": "hours",
1818
"pt": "horas"
@@ -23,9 +23,9 @@
2323
}
2424
},
2525
"Can drink water": {
26-
"Object": "2024-04-02 21:23:06-03:00",
26+
"Object": "2024-04-09 05:19:12-03:00",
2727
"Time": 40,
28-
"Time text": "21:23",
28+
"Time text": "05:19",
2929
"Unit": {
3030
"en": "minutes",
3131
"pt": "minutos"
@@ -36,9 +36,9 @@
3636
}
3737
},
3838
"Will be hungry": {
39-
"Object": "2024-04-02 23:43:06-03:00",
39+
"Object": "2024-04-09 07:39:12-03:00",
4040
"Time": 3,
41-
"Time text": "23:43",
41+
"Time text": "07:39",
4242
"Unit": {
4343
"en": "hours",
4444
"pt": "horas"

Modules/Database/Register/__init__.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -402,5 +402,14 @@ def Write_On_Diary_Slim(self):
402402

403403
from Diary_Slim.Write_On_Diary_Slim_Module import Write_On_Diary_Slim_Module as Write_On_Diary_Slim_Module
404404

405-
# Write on Diary Slim
406-
Write_On_Diary_Slim_Module(self.dictionary["Entry"]["Diary Slim"]["Text"], self.dictionary["Entry"]["Dates"]["Timezone"], add_dot = False)
405+
# Define the "Write on Diary Slim" dictionary
406+
dictionary = {
407+
"Text": self.dictionary["Entry"]["Diary Slim"]["Text"],
408+
"Time": self.dictionary["Entry"]["Dates"]["Timezone"],
409+
"Add": {
410+
"Dot": False
411+
}
412+
}
413+
414+
# Write the entry text on Diary Slim
415+
Write_On_Diary_Slim_Module(dictionary)

Modules/Diary_Slim/Create_New_Diary_Slim/__init__.py

+17-24
Original file line numberDiff line numberDiff line change
@@ -291,21 +291,18 @@ def Create_Diary_Slim_Header(self):
291291
self.dictionary["Texts"]["Diary Slim date text"] = template.format(item)
292292

293293
# Define the "type the time that you" text template
294-
type_text = self.JSON.Language.language_texts["type_the_time_that_you_{}"]
294+
template = self.JSON.Language.language_texts["type_the_time_that_you_{}"]
295295

296296
# Ask for the time the user have gone to sleep
297-
type_text = type_text.format(self.JSON.Language.language_texts["have_gone_to_sleep"])
297+
type_text = template.format(self.JSON.Language.language_texts["have_gone_to_sleep"])
298298

299299
self.dictionary["Times"]["Sleeping"] = self.Match_Time_Pattern(type_text)
300300

301301
# Ask for the time the user woke up
302-
type_text = type_text.format(self.JSON.Language.language_texts["woke_up"])
302+
type_text = template.format(self.JSON.Language.language_texts["woke_up"])
303303

304304
self.dictionary["Times"]["Waking"] = self.Match_Time_Pattern(type_text)
305305

306-
# Show a space separator
307-
print()
308-
309306
# Format the root header template, making the Diary Slim header
310307
self.dictionary["Texts"]["Header"] = self.diary_slim["Header template"].format(self.dictionary["Times"]["Sleeping"], self.dictionary["Times"]["Waking"])
311308

@@ -513,19 +510,6 @@ def Write_To_Files(self):
513510

514511
# If the Diary file Slim does not exist
515512
if self.states["Diary Slim exists"] == False:
516-
# If the "Check for skipped Diary Slim" state is True
517-
if self.states["Skipped Diary Slims"]["Check"] == True:
518-
# Show a space separator
519-
print()
520-
521-
# Show a five dash space separator
522-
print(self.separators["5"])
523-
524-
# If the "Check for skipped Diary Slim" state is False
525-
if self.states["Skipped Diary Slims"]["Check"] == False:
526-
# Show a space separator
527-
print()
528-
529513
# Get the current day file text
530514
file_text = self.File.Contents(self.dictionary["File"])["lines"]
531515

@@ -552,11 +536,20 @@ def Write_To_Files(self):
552536
current_diary_slim = False
553537

554538
# Write the full Diary Slim header text into the Diary Slim file
555-
# With the custom date
539+
# With the text and the custom date
556540
# Without the time (it is already in the full text)
557-
# Without checking for file length (no spaces on the start of file)
558-
# And with the two local verbose and current Diary Slim variables above
559-
Write_On_Diary_Slim_Module(self.dictionary["Texts"]["To write"], custom_date = self.dictionary["Dates"]["Now"], add_time = False, check_file_length = False, current_diary_slim = current_diary_slim, verbose = verbose)
541+
# And with the two local "current Diary Slim" and "verbose" variables above
542+
dictionary = {
543+
"Text": self.dictionary["Texts"]["To write"],
544+
"Date": self.dictionary["Dates"]["Now"],
545+
"Add": {
546+
"Time": False
547+
},
548+
"Current_Diary_Slim": current_diary_slim,
549+
"Verbose": verbose
550+
}
551+
552+
Write_On_Diary_Slim_Module(dictionary)
560553

561554
# Open the current Diary Slim file
562-
self.System.Open(self.dictionary["File"])
555+
self.System.Open(self.dictionary["File"], verbose = False)

Modules/Diary_Slim/Write_On_Diary_Slim/__init__.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,13 @@ def Write(self):
458458
# Show a space separator
459459
print()
460460

461+
# Define the "Write on Diary Slim" dictionary
462+
dictionary = {
463+
"Text": self.dictionary["Text to write"]
464+
}
465+
461466
# Write the text on Diary Slim
462-
Write_On_Diary_Slim_Module(self.dictionary["Text to write"])
467+
Write_On_Diary_Slim_Module(dictionary)
463468

464469
# Open the current Diary Slim file
465470
self.System.Open(self.diary_slim["Current year"]["Current Diary Slim file"])

Modules/Diary_Slim/Write_On_Diary_Slim_Module/__init__.py

+104-39
Original file line numberDiff line numberDiff line change
@@ -3,65 +3,130 @@
33
from Diary_Slim.Diary_Slim import Diary_Slim as Diary_Slim
44

55
class Write_On_Diary_Slim_Module(Diary_Slim):
6-
def __init__(self, text, time = None, custom_date = None, add_time = True, show_text = True, add_dot = True, check_file_length = True, current_diary_slim = True, verbose = None):
6+
def __init__(self, dictionary = {}):
77
super().__init__()
88

9-
self.text = text
10-
self.custom_date = custom_date
11-
self.time = time
12-
self.add_time = add_time
13-
self.show_text = show_text
14-
self.check_file_length = check_file_length
15-
self.current_diary_slim = current_diary_slim
16-
self.verbose = verbose
17-
18-
if (
19-
self.text[-1] != "." and
20-
add_dot == True
21-
):
22-
self.text += "."
9+
# Define the root dictionary
10+
self.dictionary = {
11+
"Texts": {
12+
"To write": "",
13+
"To show": ""
14+
},
15+
"Time string": "",
16+
"Date": self.date,
17+
"Show text": True,
18+
"Add": {
19+
"Time": True,
20+
"Dot": True
21+
},
22+
"Current Diary Slim": True,
23+
"Verbose": True
24+
}
25+
26+
# Get the keys and values from the "dictionary" parameter
27+
28+
# Get the "Text" key
29+
if "Text" in dictionary:
30+
self.dictionary["Texts"]["To write"] = dictionary["Text"]
31+
32+
# Get the "Time" key
33+
if "Time" in dictionary:
34+
self.dictionary["Time string"] = dictionary["Time"]
35+
36+
# Get the "Date" key
37+
if "Date" in dictionary:
38+
self.dictionary["Date"] = dictionary["Date"]
39+
40+
# Update the "Add" dictionary
41+
if "Add" in dictionary:
42+
for key in dictionary["Add"]:
43+
self.dictionary["Add"][key] = dictionary["Add"][key]
44+
45+
# Update the "Current Diary Slim" and "Verbose" keys
46+
keys = [
47+
"Show text",
48+
"Current Diary Slim",
49+
"Verbose"
50+
]
51+
52+
for key in keys:
53+
if key in dictionary:
54+
self.dictionary[key] = dictionary[key]
2355

2456
self.Write()
2557

2658
def Write(self):
27-
if self.time == None:
28-
self.time = self.Date.Now()["Formats"]["HH:MM DD/MM/YYYY"]
29-
30-
text_to_append = ""
59+
# If the time string is empty, get a time string from the current date
60+
if self.dictionary["Time string"] == "":
61+
self.dictionary["Time string"] = self.Date.Now()["Formats"]["HH:MM DD/MM/YYYY"]
3162

32-
if self.add_time == True:
33-
text_to_append += self.time + ":\n"
34-
35-
text_to_append += self.text
36-
37-
if self.check_file_length == True:
38-
text_to_append = "\n\n" + text_to_append
63+
# If the "Add time" switch is True
64+
if self.dictionary["Add"]["Time"] == True:
65+
# Add the time string
66+
self.dictionary["Texts"]["To write"] = self.dictionary["Time string"] + ":\n" + self.dictionary["Texts"]["To write"]
3967

4068
# Get the current Diary Slim dictionary
41-
current_diary_slim = self.Current_Diary_Slim(date = self.custom_date, current_diary_slim = self.current_diary_slim)
69+
current_diary_slim = self.Current_Diary_Slim(date = self.dictionary["Date"], current_diary_slim = self.dictionary["Current Diary Slim"])
4270

4371
# Create the file
4472
self.File.Create(current_diary_slim["File"])
4573

46-
# Edit the file with the new text
47-
self.File.Edit(current_diary_slim["File"], text_to_append, "a", next_line = False, verbose = self.verbose)
74+
# Get the length of the file
75+
length = self.File.Contents(current_diary_slim["File"])["length"]
76+
77+
# If the file is not empty, add line breaks before the text
78+
if length != 0:
79+
self.dictionary["Texts"]["To write"] = "\n\n" + self.dictionary["Texts"]["To write"]
80+
81+
# If the last character of the text is not a dot
82+
# And the "Add dot" switch is True
83+
if (
84+
self.dictionary["Texts"]["To write"][-1] != "." and
85+
self.dictionary["Add"]["Dot"] == True
86+
):
87+
# Add a dot to the end of the text
88+
self.dictionary["Texts"]["To write"] += "."
4889

90+
# Add the text to the file
91+
self.File.Edit(current_diary_slim["File"], self.dictionary["Texts"]["To write"], "a", next_line = False, verbose = self.dictionary["Verbose"])
92+
93+
# If the "verbose" switch is True, show a space separator
4994
if self.switches["verbose"] == True:
5095
print()
5196

52-
self.text_to_show = self.language_texts["this_text_was_written_to_the_current_diary_slim"] + ":"
97+
# Define the text to show as the "This text was written to the current Diary Slim" text
98+
self.dictionary["Texts"]["To show"] = self.language_texts["this_text_was_written_to_the_current_diary_slim"] + ":"
5399

100+
# If the "testing" switch is True
54101
if self.switches["testing"] == True:
55-
self.text_to_show = self.text_to_show.replace(self.JSON.Language.language_texts["was"], self.JSON.Language.language_texts["was_not"])
56-
self.text_to_show = self.text_to_show.replace(":", " (" + self.language_texts["testing_is_true"] + "):")
102+
# Update the information telling the user that the text was not written to the file
103+
# Because the "testing" switch is True
104+
105+
# Replace "was" with "was not"
106+
replace = self.JSON.Language.language_texts["was"]
107+
with_ = self.JSON.Language.language_texts["was_not"]
57108

58-
if text_to_append[0] == "\n":
59-
text_to_append = text_to_append[2:]
109+
self.dictionary["Texts"]["To show"] = self.dictionary["Texts"]["To show"].replace(replace, with_)
60110

61-
self.text_to_show += "\n" + "[" + text_to_append + "]"
111+
# Add the information about the "testing" switch being True
112+
replace = ":"
113+
with_ = " (" + self.language_texts["testing_is_true"] + "):"
62114

63-
if self.show_text == True and self.verbose == None:
64-
print(self.text_to_show)
115+
self.dictionary["Texts"]["To show"] = self.dictionary["Texts"]["To show"].replace(replace, with_)
65116

66-
def __str__(self):
67-
return self.text_to_show
117+
# If the first character of the text to write is a line break
118+
if self.dictionary["Texts"]["To write"][0] == "\n":
119+
# Remove it
120+
self.dictionary["Texts"]["To write"] = self.dictionary["Texts"]["To write"][2:]
121+
122+
# Add the text to write to the text to show
123+
self.dictionary["Texts"]["To show"] += "\n" + "[" + self.dictionary["Texts"]["To write"] + "]"
124+
125+
# If the "Show text" switch is True
126+
# And the "Verbose" switch is True
127+
if (
128+
self.dictionary["Show text"] == True and
129+
self.dictionary["Verbose"] == True
130+
):
131+
# Show the text to show
132+
print(self.dictionary["Texts"]["To show"])

Modules/GamePlayer/Register/__init__.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -710,4 +710,14 @@ def Write_On_Diary_Slim(self):
710710

711711
from Diary_Slim.Write_On_Diary_Slim_Module import Write_On_Diary_Slim_Module as Write_On_Diary_Slim_Module
712712

713-
Write_On_Diary_Slim_Module(self.dictionary["Entry"]["Diary Slim"]["Text"], self.dictionary["Entry"]["Dates"]["Timezone"], add_dot = False, current_diary_slim = False)
713+
# Define the "Write on Diary Slim" dictionary
714+
dictionary = {
715+
"Text": self.dictionary["Entry"]["Diary Slim"]["Text"],
716+
"Time": self.dictionary["Entry"]["Dates"]["Timezone"],
717+
"Add": {
718+
"Dot": False
719+
}
720+
}
721+
722+
# Write the entry text on Diary Slim
723+
Write_On_Diary_Slim_Module(dictionary)

Modules/SproutGigs/Work/__init__.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,13 @@ def __init__(self):
6666
print(self.website["name"])
6767
print()
6868

69-
Write_On_Diary_Slim_Module(self.language_texts["i_worked_a_little_on"] + " " + '"' + self.website["name"] + '"')
69+
# Define the "Write on Diary Slim" dictionary
70+
dictionary = {
71+
"Text": self.language_texts["i_worked_a_little_on"] + " " + '"' + self.website["name"] + '"'
72+
}
73+
74+
# Write the entry text on Diary Slim
75+
Write_On_Diary_Slim_Module(dictionary)
7076

7177
self.finish_working = True
7278

Modules/Stories/Stories/__init__.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,15 @@ def Register_Task(self, task_dictionary, register_task = True):
881881

882882
from Diary_Slim.Write_On_Diary_Slim_Module import Write_On_Diary_Slim_Module as Write_On_Diary_Slim_Module
883883

884-
Write_On_Diary_Slim_Module(task_dictionary["Task"]["Descriptions"][self.user_language], self.task_dictionary["Date"]["Formats"]["HH:MM DD/MM/YYYY"], show_text = False, current_diary_slim = False)
884+
# Define the "Write on Diary Slim" dictionary
885+
dictionary = {
886+
"Text": task_dictionary["Task"]["Descriptions"][self.user_language]
887+
"Time": self.task_dictionary["Date"]["Formats"]["HH:MM DD/MM/YYYY"],
888+
"Show text": False
889+
}
890+
891+
# Write the entry text on Diary Slim
892+
Write_On_Diary_Slim_Module(dictionary)
885893

886894
def Select_Story(self, select_text_parameter = None, select_class = False):
887895
# Define the show text

Modules/Tasks/Register/__init__.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -470,5 +470,15 @@ def Write_On_Diary_Slim(self):
470470

471471
from Diary_Slim.Write_On_Diary_Slim_Module import Write_On_Diary_Slim_Module as Write_On_Diary_Slim_Module
472472

473-
# Write on Diary Slim
474-
Write_On_Diary_Slim_Module(self.dictionary["Entry"]["Diary Slim"]["Text"], self.dictionary["Entry"]["Dates"]["Timezone"], add_dot = False, show_text = False, current_diary_slim = False)
473+
# Define the "Write on Diary Slim" dictionary
474+
dictionary = {
475+
"Text": self.dictionary["Entry"]["Diary Slim"]["Text"],
476+
"Time": self.dictionary["Entry"]["Dates"]["Timezone"],
477+
"Add": {
478+
"Dot": False
479+
},
480+
"Show text": False
481+
}
482+
483+
# Write the entry text on Diary Slim
484+
Write_On_Diary_Slim_Module(dictionary)

0 commit comments

Comments
 (0)