Help with Python Script

I have a script to go from ChannelsDVR Json to sage Properties but I need to replace some characters in Genre and year. any hep is appreciated.

I am getting this ....
Title=A Few Good Men (1992)
Description=Navy lawyers (Tom Cruise, Demi Moore) defend Marines for a murder at Gitmo.
Genre=['Drama']
Year=1992-12-11T00:00:00Z

Need this ..
Title=A Few Good Men (1992)
Description=Navy lawyers (Tom Cruise, Demi Moore) defend Marines for a murder at Gitmo.
Genre=Drama
Year=1992

#! /usr/bin/python

import json

json_file = 'c:/Python/A Few Good Men (1992) 2021-05-22-1959.json'

with open(json_file) as json_data:
    data = json.load(json_data)

json_data.close()

outfile=open('c:/python/output.txt', 'w')

print ("Title={}".format(data['Title']), file=outfile)
print ("Description={}".format(data['Description']), file=outfile)
print ("Genre={}".format(data['Genres']), file=outfile)
print ("Year={}".format(data['OriginalBroadcastDateTime']), file=outfile)

outfile.close()

Don't know python, but...
For a movie, ReleaseYear contains just the 4-digit year number.
Genres can have multiple values, maybe you just want to extract the first one???

I'm sure jq could do what you want, unless it has to be python.

Can you post or send me the .json file?

{"Description":"Navy lawyers (Tom Cruise, Demi Moore) defend Marines for a murder at Gitmo.","Episode":0,"Genres":["Drama"],"IsMovie":true,"IsNews":false,"IsSports":false,"MetadataGenerator":"Channels DVR","OriginalBroadcastDateTime":"1992-12-11T00:00:00Z","RecordedDateTime":"2021-05-23T03:00:00Z","Season":0,"SubTitle":"","Title":"A Few Good Men (1992)"}

Finally got it with a lot of help from my friends ...

print ("Genre={}".format("/".join(data['Genres'])), file=outfile)
print ("Year={}".format(data['OriginalBroadcastDateTime'].split("-")[0]), file=outfile)

print ("Genre={}".format(data['Genres'][0]))
print ("Year={}".format(datetime.strptime(data['OriginalBroadcastDateTime'], '%Y-%m-%dT%H:%M:%SZ').strftime('%Y')))
1 Like