From 6de39b63f50454917d28a91fff9e242a7944ae18 Mon Sep 17 00:00:00 2001 From: 64Core <64core@pm.me> Date: Wed, 29 Mar 2023 22:59:22 -0500 Subject: [PATCH] PR #77 Tidying Pathlib code --- itchiodl/game.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/itchiodl/game.py b/itchiodl/game.py index c37a561..5ec34f1 100644 --- a/itchiodl/game.py +++ b/itchiodl/game.py @@ -90,7 +90,7 @@ class Game: continue self.do_download(d, token) - with open(f"{self.destination_path}.json", "w") as f: + with self.destination_path.with_suffix(".json").open(mode="w") as f: json.dump( { "name": self.name, @@ -110,8 +110,8 @@ class Game: filename = utils.clean_path(d["filename"] or d["display_name"] or d["id"]) filepath = Path(f"{self.destination_path}/{filename}") - hashpath = Path(f"{self.destination_path}/{filename}.md5") - oldpath = Path(f"{self.destination_path}/old") + hashpath = filepath.with_suffix(".md5") + if filepath.exists(): print(f"File Already Exists! {filename}") if hashpath.exists(): @@ -135,12 +135,12 @@ class Game: # if corrupted: # filename.remove() # return - - oldpath.mkdir() + old_dir = self.destination_path / "old" + old_dir.mkdir(exist_ok=True) print(f"Moving {filename} to old/") timestamp = datetime.datetime.now().strftime("%Y-%m-%d") - filename.rename(oldpath / f"{timestamp}-{filename}") + filename.rename(old_dir / f"{timestamp}-{filename}") # Get UUID r = requests.post(