Spaces:
Sleeping
Sleeping
| from motor.motor_asyncio import AsyncIOMotorClient | |
| from config import settings | |
| import uuid | |
| import asyncio | |
| async def main(): | |
| client = AsyncIOMotorClient(settings.mongo_uri) | |
| db = client[settings.mongo_db_name] | |
| companies = db["Companies"] | |
| print("Successfully connected to Companies Database") | |
| company_name = "Test Company" | |
| chatbot_name = "Test Chat" | |
| company_id = str(uuid.uuid5(uuid.NAMESPACE_DNS, company_name)) | |
| chatbot_id = str(uuid.uuid5(uuid.NAMESPACE_DNS, chatbot_name)) | |
| # Insert company if it doesn't exist | |
| await companies.update_one( | |
| {"_id": company_id}, | |
| {"$setOnInsert": {"company_name": company_name, "chatbots": []}}, | |
| upsert=True | |
| ) | |
| # Add chatbot object to company's chatbots array | |
| await companies.update_one( | |
| {"_id": company_id}, | |
| {"$addToSet": {"chatbots": {"chatbot_id": chatbot_id, "name": chatbot_name}}} | |
| ) | |
| print("Company ID:", company_id) | |
| print("Chatbot ID:", chatbot_id) | |
| asyncio.run(main()) | |