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