diff --git a/helpers/mongo.py b/helpers/mongo.py index c51adf8..d7dbce3 100644 --- a/helpers/mongo.py +++ b/helpers/mongo.py @@ -10,6 +10,9 @@ class Mongo: url = f"mongodb://{settings.MONGO_USER}:{settings.MONGO_PASSWORD}@{settings.MONGO_HOST}:27017/" self.client = pymongo.MongoClient(url) self.database = self.client.get_database("b-jokes") + self.jokes_collection.create_index([ + ("id", 1) + ]) def __getitem__(self, item): return self.database.get_collection(item) diff --git a/processor.py b/processor.py index 0bb258d..495d3e7 100644 --- a/processor.py +++ b/processor.py @@ -1,5 +1,8 @@ +import random from functools import cached_property +from helpers.mongo import mongo + class Processor: def __init__(self, data: dict): @@ -8,10 +11,17 @@ class Processor: self.message = data['request']['original_utterance'] 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): - ... + return { + "text": "Функционал пока в разработке" + } def finish(self): return {