get random
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user