import json import os import sys compiled = [] for json_file in sys.argv[1:]: jfile = json.load(open(json_file)) for beer in jfile: year = 2000 + beer['added'][2] abv = beer['abv'] ratings = beer['ratings'] av_rating = beer['rating'] if (ratings >= 15) and (av_rating is not None) and (abv is not None) and (year < 2021): compiled.append({ 'added': { 'year': year, 'month': beer['added'][0], 'day': beer['added'][1], }, 'brewery': os.path.basename(json_file).split('.')[0], 'name': beer['name'], 'style': beer['style'], 'abv': abv, 'ratings': { 'count': ratings, 'average': av_rating }, 'in_production': beer['in_production'] }) print(json.dumps(compiled))