3
3
from Diary_Slim .Diary_Slim import Diary_Slim as Diary_Slim
4
4
5
5
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 = {} ):
7
7
super ().__init__ ()
8
8
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 ]
23
55
24
56
self .Write ()
25
57
26
58
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" ]
31
62
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" ]
39
67
40
68
# 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" ] )
42
70
43
71
# Create the file
44
72
self .File .Create (current_diary_slim ["File" ])
45
73
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" ] += "."
48
89
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
49
94
if self .switches ["verbose" ] == True :
50
95
print ()
51
96
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" ] + ":"
53
99
100
+ # If the "testing" switch is True
54
101
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" ]
57
108
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_ )
60
110
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" ] + "):"
62
114
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_ )
65
116
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" ])
0 commit comments