import edgedb import json import os from dotenv import load_dotenv load_dotenv() client = edgedb.create_client() for root, dirs, files in os.walk("../Banco_de_Dados/Coleta/downloaded_files"): for file in files: if file.endswith(".json"): with open(os.path.join(root, file), 'r') as f: data = json.load(f) data_path = './'+'/'.join(root.split('/')[5:]) # Insert Website client.query(''' INSERT Website { url := $url, relative_path := $relative_path, hyperrefs := >$gov_links, images := {}, videos := {}, text := ( INSERT Text { content := $content } ) }; ''', url=data['absolute_url'], \ relative_path=data_path, \ gov_links=data['gov_links'], \ content=data['text']) # Insert Images for image in data.get('images', []): client.query(''' UPDATE Website FILTER .url = $url SET { images += { (INSERT Image { name := $name, path := $path, url := $image_url, hyperlink := $hyperlink, alt := $alt, }) } }; ''', url=data['absolute_url'], \ path=image['path'], \ name=image['name'], \ image_url=image['url'], \ hyperlink=image['hyperlink'], \ alt=image['alt']) for video in data.get('videos', []): client.query(''' UPDATE Website FILTER .url = $url SET { videos += { (INSERT Video { name := $name, url := $video_url, hyperlink := $hyperlink, alt := $alt, }) } }; ''', url=data['absolute_url'], \ name=video['name'], \ video_url=video['url'], \ hyperlink=video['hyperlink'], \ alt=video['alt'])