From 163a53b972888884d532efa9c3957371e267d1e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Fri, 29 Dec 2023 11:25:04 +0100 Subject: [PATCH] steam_owned_games_readable: add --- steam_owned_games_readable.py | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 steam_owned_games_readable.py diff --git a/steam_owned_games_readable.py b/steam_owned_games_readable.py new file mode 100644 index 0000000..6887f7e --- /dev/null +++ b/steam_owned_games_readable.py @@ -0,0 +1,43 @@ +import json +import argparse +from datetime import datetime, timezone + + +def process_json_file(filename): + # Read JSON data from file + with open(filename, "r") as file: + data = json.load(file) + + # Process each game + for game in data["response"]["games"]: + # Convert playtime from minutes to hours + game["playtime_forever"] /= 60 + + # Convert Unix timestamp to readable date and time in UTC + if game["rtime_last_played"] != 0: + game["rtime_last_played"] = datetime.fromtimestamp( + game["rtime_last_played"], timezone.utc + ).strftime("%Y-%m-%d %H:%M:%S") + else: + game["rtime_last_played"] = "Not Played" + + # Return the modified data + return data + + +def main(): + parser = argparse.ArgumentParser( + description="Process a JSON file containing game data." + ) + parser.add_argument("filename", help="JSON file to be processed") + args = parser.parse_args() + + # Process the JSON file + modified_data = process_json_file(args.filename) + + # Print the modified data + print(json.dumps(modified_data, indent=4)) + + +if __name__ == "__main__": + main()