I need to comapre the titles in this Json file with the titles in a list. My goal is to check what titles are equal to the values of this list and then print information about that title. For example if one of the titles is Bloons TD 6 I want to only print the corresponding description and viewableDate.
Here is what I have so far
response = requests.get("https://store-site-backend-static-ipv4.ak.epicgames.com/freeGamesPromotions?locale=en-US&country=US&allowCountries=US")
freeGameData = json.loads(response.text)
freeNowList = Epic_Scraper()
#freeNowList returns ['Bloons TD 6', 'Loop Hero']
#freeGameData returns the json listed below
The Json File looks like this
{
"data": {
"Catalog": {
"searchStore": {
"elements": [
{
"title": "Loop Hero",
"id": "db122f42b41f4dec927e0f280cf653bd",
"namespace": "ff50f85ed609454e80ac46d9496da34d",
"description": "The Lich has thrown the world into a timeless loop and plunged its inhabitants into never ending chaos. Wield an expanding deck of mystical cards to place enemies, buildings, and terrain along each unique expedition loop for the brave hero.",
"effectiveDate": "2021-03-04T18:00:00.000Z",
"offerType": "BASE_GAME",
"expiryDate": null,
"viewableDate": "2021-03-04T18:00:00.000Z",
"status": "ACTIVE",
"isCodeRedemptionOnly": false,
},
{
"title": "Bloons TD 6",
"id": "b27e3b556f1048b9824c7196f32afceb",
"namespace": "6a8dfa6e441e4f2f9048a98776c6077d",
"description": "The Bloons are back and better than ever! Get ready for a massive 3D tower defense game designed to give you hours and hours of the best strategy gaming available.",
"effectiveDate": "2022-07-19T12:00:00.000Z",
"offerType": "BASE_GAME",
"expiryDate": null,
"viewableDate": "2022-04-30T00:00:00.000Z",
"status": "ACTIVE",
"isCodeRedemptionOnly": false,
},
{
"title": "Destiny 2: Bungie 30th Anniversary Pack",
"id": "e7b9e222c7274dd28714aba2e06d2a01",
"namespace": "428115def4ca4deea9d69c99c5a5a99e",
"description": "The 30th Anniversary Pack includes a new Dungeon, Gjallarhorn Exotic Rocket Launcher, new weapons, armor, and much more. ",
"effectiveDate": "2022-08-23T13:00:00.000Z",
"offerType": "DLC",
"expiryDate": null,
"viewableDate": "2022-08-08T15:00:00.000Z",
"status": "ACTIVE",
"isCodeRedemptionOnly": false,
},
},
}
>Solution :
Loop through the innermost list of your json and only print the information if the title is in your list:
for e in freeGameData["data"]["Catalog"]["searchStore"]["elements"]:
if e["title"] in freeNowList:
print(e["description"])
print(e["viewableDate"]+"\n")