steam_owned_games_readable: add

This commit is contained in:
Lukáš Kucharczyk 2023-12-29 11:25:04 +01:00
parent f9faf4f8a4
commit 163a53b972
Signed by: lukas
SSH Key Fingerprint: SHA256:vMuSwvwAvcT6htVAioMP7rzzwMQNi3roESyhv+nAxeg
1 changed files with 43 additions and 0 deletions

View File

@ -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()