I hope you're well :) I'm beginner with Python. I hope my message will be clear
I'll try to summarize. I've some blog posts with a title (which a name of a recipe, for instance Salade Nicoise) and a picture only. I'd like to match the title of my blog post with the recipe of my json (which full of recipes).
Here is a code to display all the json:
import pandas as pd
import json
import re
class Exemple:
def __init__(self, titre, image, url, temps, tempsprep, tempscui, autor, autorlink, typerecipe, recipe, peoplequantity, ingredients, reputation, difficulte, budget):
self.titre = titre
self.image = image
self.url = url
self.temps = temps
self.tempsprep = tempsprep
self.tempscui = tempscui
self.autor = autor
self.autorlink = autorlink
self.typerecipe = typerecipe
self.recipe = recipe
self.peoplequantity = peoplequantity
self.ingredients = ingredients
self.reputation = reputation
self.difficulte = difficulte
self.budget = budget
@classmethod
def from_json(cls, json_string):
json_dict = json.loads(json_string)
return cls(**json_dict)
def __repr__(self):
return f'{ self.titre }, { self.image }, { self.url }, { self.temps }, { self.tempsprep }, { self.tempscui }, { self.autor }, { self.autorlink }, { self.typerecipe }, { self.recipe }, { self.peoplequantity }, { self.ingredients }, { self.reputation }, { self.difficulte }, { self.budget }, '
with open('exemple.json', 'r') as json_file:
list_data = json.loads(json_file.read())
for l in list_data:
check_list.append(Exemple(**l))
print(check_list)
For instance: the name of my post is Salade Nicoise. I'd like to search in my json the 'titre'
which is the closest to Salade Nicoise (sometimes: La Salade Niçoise la vraie or La Salade Nicoise, etc) and display the infos of the json on my post. Do you have any ideas?
I've tried to do it with pandas but if it's not exactly the same title that's does not match.
df = pd.read_json('exemple.json')
dtitre = df.loc[df['titre'] == 'Mousse de foies de volaille']
print (dtitre[['titre', 'ingredients', 'reputation']])
I'll be happy if you can help me guys,