Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
fix: files not opening due to relative path issues
Browse files Browse the repository at this point in the history
  • Loading branch information
seesmof committed Dec 22, 2023
1 parent 9a50aac commit 2d1af2a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 23 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,4 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

data/
#.idea/
4 changes: 1 addition & 3 deletions Run.bat
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
@echo off

if not exist "./data/requirements.txt" (
echo Installing requirements...
pip install -r requirements.txt
echo Requirements installed successfully > "./data/requirements.txt"
)

python ./src/main.py
exit
pause
Empty file added data/latest.md
Empty file.
6 changes: 5 additions & 1 deletion src/components/PopularWords.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from os import path
from customtkinter import *

from util.utils import getPopularWords
Expand Down Expand Up @@ -30,7 +31,10 @@ def updateWords(self):
widget.destroy()

words = []
with open("data/latest.md", encoding="utf-8") as f:
currentDir = path.dirname(path.abspath(__file__))
dataFile = path.join(currentDir, "..", "..", "data", "latest.md")

with open(dataFile, "r", encoding="utf-8") as f:
for line in f:
words.extend(line.split())

Expand Down
31 changes: 17 additions & 14 deletions src/ui/ui.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from os import path
from customtkinter import *
from rich.console import Console

Expand Down Expand Up @@ -137,7 +138,9 @@ def showPopularWords(text):

def saveTextToFile(text):
try:
filePath = f"data/{generateFileName(text)}.md"
fileName = generateFileName(text)
currentDir = path.dirname(path.abspath(__file__))
filePath = path.join(currentDir, "..", "..", "data", fileName + ".md")
except Exception as e:
console.log(
"Failed to save text to file, most likely due to input field being empty"
Expand Down Expand Up @@ -202,16 +205,16 @@ def renderMainTab(root) -> CTkTextbox:
),
)

try:
with open("data/latest.md", encoding="utf-8") as f:
loadedText = f.read()
getTextInput.insert("0.0", loadedText)
updateMetrics(
loadedText,
resultsLines,
resultsSymbols,
resultsWords,
resultsReadingTime,
)
except Exception as e:
console.log("Failed to load file")
currentDir = path.dirname(path.abspath(__file__))
dataFile = path.join(currentDir, "..", "..", "data", "latest.md")

with open(dataFile, "r", encoding="utf-8") as f:
loadedText = f.read()
getTextInput.insert("0.0", loadedText)
updateMetrics(
loadedText,
resultsLines,
resultsSymbols,
resultsWords,
resultsReadingTime,
)
7 changes: 5 additions & 2 deletions src/util/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import date
from os import path
from pathlib import Path
from string import punctuation
from rich.console import Console
Expand Down Expand Up @@ -75,5 +76,7 @@ def generateFileName(text: str) -> str:

def saveCurrentText(text: str) -> None:
text = [line.strip() for line in text.split("\n") if line.strip()]
filePath = Path("data/latest.md")
filePath.write_text("\n".join(text), encoding="utf-8")
currentDir = path.dirname(path.abspath(__file__))
dataFile = path.join(currentDir, "..", "..", "data", "latest.md")
with open(dataFile, "w", encoding="utf-8") as f:
f.write("\n".join(text))

0 comments on commit 2d1af2a

Please sign in to comment.