This commit is contained in:
Administrator 2022-10-03 17:09:47 +03:00
parent 96bb2c8701
commit 21099cda55
2 changed files with 15 additions and 2 deletions

View File

@ -10,6 +10,9 @@ class Mongo:
url = f"mongodb://{settings.MONGO_USER}:{settings.MONGO_PASSWORD}@{settings.MONGO_HOST}:27017/" url = f"mongodb://{settings.MONGO_USER}:{settings.MONGO_PASSWORD}@{settings.MONGO_HOST}:27017/"
self.client = pymongo.MongoClient(url) self.client = pymongo.MongoClient(url)
self.database = self.client.get_database("b-jokes") self.database = self.client.get_database("b-jokes")
self.jokes_collection.create_index([
("id", 1)
])
def __getitem__(self, item): def __getitem__(self, item):
return self.database.get_collection(item) return self.database.get_collection(item)

View File

@ -1,5 +1,8 @@
import random
from functools import cached_property from functools import cached_property
from helpers.mongo import mongo
class Processor: class Processor:
def __init__(self, data: dict): def __init__(self, data: dict):
@ -8,10 +11,17 @@ class Processor:
self.message = data['request']['original_utterance'] self.message = data['request']['original_utterance']
def next(self): def next(self):
... count_docs = mongo.jokes_collection.count_documents({})
rnd = random.randrange(count_docs)
anek = mongo.jokes_collection.find_one({"id": rnd})
return {
"text": anek['text']
}
def save(self): def save(self):
... return {
"text": "Функционал пока в разработке"
}
def finish(self): def finish(self):
return { return {