get random

This commit is contained in:
Administrator
2022-10-05 17:54:53 +03:00
parent af3948cd0f
commit 501c1b2ccf
2 changed files with 12 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
import logging
import random
from time import sleep
from requests import get
@@ -27,6 +28,13 @@ def fetch_jokes():
i += 1
def get_random() -> str:
count_docs = mongo.jokes_collection.count_documents({})
rnd = random.randrange(1, count_docs + 1)
anek = mongo.jokes_collection.aggregate([{"$sample": {"size": 1}}])[0]
return anek['text']
def poll_jokes():
while True:
logging.info("start fetching jokes")