-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileManager.py
55 lines (47 loc) · 1.66 KB
/
fileManager.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
from datetime import datetime
separation_mark = "===================="
class fileManager:
def __init__(self):
None
def saveToTxt(self, text):
try:
with open("gptSummary.txt", "a") as f:
currentTime = datetime.now()
currentTimeFormatted = currentTime.strftime("%Y-%m-%d %H:%M:%S")
f.write("time when written: " + currentTimeFormatted + "\n")
f.write(text + "\n")
f.write(separation_mark + "\n")
print("wrote to gptSummary.txt succesfully")
except Exception as e:
print("an IO error occured:")
print(e)
return e
def readMostRecentFromTxt(self):
summary = ""
currentLine = ""
try:
with open("gptSummary.txt", "r") as f:
while (currentLine != separation_mark + "\n"):
currentLine = f.readline()
summary += currentLine + "\n"
return summary
except Exception as e:
print("En IO-feil har skjedd")
print(e)
return e
def readAllfromTxt(self):
summaries = ""
currentLine = "_"
try:
with open("gptSummary.txt", "r") as f:
while (currentLine != ""):
currentLine = f.readline()
if (currentLine != separation_mark):
summaries += currentLine
else:
summaries += "\n \n"
return summaries
except Exception as e:
print("En IO-feil har skjedd")
print(e)
return e