steam_owned_games_readable: add
This commit is contained in:
parent
f9faf4f8a4
commit
163a53b972
|
@ -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()
|
Loading…
Reference in New Issue