From 855e4a8f10ebc6fc17e876cba5c9b343dce48f6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BF=AB=E4=B9=90=E7=9A=84=E8=80=81=E9=BC=A0=E5=AE=9D?= =?UTF-8?q?=E5=AE=9D?= Date: Sat, 16 Mar 2024 15:56:14 +0800 Subject: [PATCH] fix: don't allow empty file and check folder's existance 1. default empty data.json will cause error, remove it please. 2. check if `/output` folder exist before open a file handle. --- .gitignore | 6 +++++- Converter.py | 5 +++++ README.md | 2 +- input/.gitkeep | 0 input/data.json | 1 - 5 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 input/.gitkeep delete mode 100644 input/data.json diff --git a/.gitignore b/.gitignore index 8c1be54..6be6546 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ /test.py -/piecharttest.py \ No newline at end of file +/piecharttest.py +*.idea +*.vscode +*output +*.json diff --git a/Converter.py b/Converter.py index c183bc7..d58c8a2 100644 --- a/Converter.py +++ b/Converter.py @@ -34,6 +34,9 @@ with open(fileName) as json_file: data = json.load(json_file) + if data=={}: + print("data is empty") + exit(-1) #0 @@ -67,6 +70,8 @@ def BarGraph(): what = str(input("Do you want to save this? (y/n): ")).lower() if what == "y": name = str(input("Enter the name for the file: ")) + if not os.path.exists("./output/"): + os.mkdir("./output/") plt.savefig("./output/" + name) print("File saved!") plt.show() diff --git a/README.md b/README.md index 87a6cf4..8caa648 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,6 @@ ## Steps 1. Export your WakaTime coding activity as json [here](https://wakatime.com/settings/account) -2. Replace the data.json file with the new json file +2. Put your json file in `/input` folder, one file per run. 3. Run Converter.py 4. Choose your option diff --git a/input/.gitkeep b/input/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/input/data.json b/input/data.json deleted file mode 100644 index 0967ef4..0000000 --- a/input/data.json +++ /dev/null @@ -1 +0,0 @@ -{}