libere-tes-chaine-de-mots/import_data/utils/documents_to_database.py

11 lines
434 B
Python
Raw Permalink Normal View History

import tqdm
from .typesense_client import client
def documents_to_database(documents_list, os_client=client):
try:
for document in tqdm.tqdm(documents_list.to_dict(orient='records')):
os_client.collections['social_media_posts'].documents.create(document)
print(f"Successfully inserted {len(documents_list)} documents.")
except Exception as e:
print(f"Error inserting documents: {str(e)}")