From 0345409ad2a1906c972cfbee5280f34b89bce8d9 Mon Sep 17 00:00:00 2001 From: anne Date: Tue, 30 May 2023 01:56:02 +0200 Subject: [PATCH] fix filename handling --- logviewer.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/logviewer.py b/logviewer.py index 1ddadd9..1bda092 100644 --- a/logviewer.py +++ b/logviewer.py @@ -326,13 +326,19 @@ class PesterLogViewer(QtWidgets.QDialog): self.hilight.rehighlight() def fileToMonthYear(self, fname): - time = strptime( - fname[(fname.index(".") + 1) : fname.index(".txt")], "%Y-%m-%d.%H.%M" - ) + time = strptime(fname[-20:-4], "%Y-%m-%d.%H.%M") + # #pesterchum.online.2023-05-27.00.54.txt + # ^^^^^^^^^^^^^^^^ + # Doesnt raise an exception if the memo name has one or more periods like the old one + # But also is not as dynamic. Could also be solved by a regex or counting how many periods are in there total, + # but this seemed like a simple approach, assuming the format doesnt change anytime soon, which seems unlikely :P + # Also doesnt fail if a memo contains ".txt" like the old way + # old fromat -> fname[(fname.index(".") + 1) : fname.index(".txt")], "%Y-%m-%d.%H.%M" + # ~ (lis)anne return [strftime("%B", time), strftime("%Y", time)] def fileToTime(self, fname): - timestr = fname[(fname.index(".") + 1) : fname.index(".txt")] + timestr = fname[-20:-4] return strftime("%a %d %b %Y %H %M", strptime(timestr, "%Y-%m-%d.%H.%M")) def timeToFile(self, time):