done
This commit is contained in:
parent
96bb2c8701
commit
21099cda55
@ -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)
|
||||
|
14
processor.py
14
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user