diff --git a/player_games.py b/player_games.py index 96cb292..b584a68 100644 --- a/player_games.py +++ b/player_games.py @@ -17,8 +17,14 @@ def playerArchives(username): url = f"https://api.chess.com/pub/player/{username}/games/archives" archive = requests.get(url, headers=headers).json()['archives'] - file_path = os.getcwd() - file_name = os.path.join(file_path, username+'_archive.txt') + try: + cwd = os.getcwd() + path = os.path.join(cwd, 'archives') + os.makedirs(path) + except OSError: + pass + + file_name = os.path.join(path, username+'_archive.txt') with open(file_name, 'w') as f: json.dump(archive, f) @@ -48,12 +54,6 @@ def playerMonthly(url=None): # Multithreaded games download def threddGames(username=None, archive=None): - try: - path = os.getcwd()+'/archives' - os.makedirs(path) - except OSError: - pass - if archive: with open(archive) as f: archive = json.load(f)