-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcore.py
33 lines (22 loc) · 819 Bytes
/
core.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import vk
from random import randint
from time import sleep
FUNNY_THRESHOLD = 2000
SLEEP_INTERVAL = 0.5
VK_API_VERSION = 5.131
token = os.getenv('ACCESS_TOKEN')
api = vk.API(access_token=token)
def get_random_anek(funny_only=False):
while True:
sleep(SLEEP_INTERVAL) # prevent vk.exceptions.VkAPIError: Too many requests per second
count = api.wall.get(v=VK_API_VERSION, domain='jumoreski', owner_id=-92876084, count=1)['count']
c = randint(0, count)
r = api.wall.get(v=VK_API_VERSION, domain='jumoreski', owner_id=-92876084, count=1, offset=c)
if len(r['items']) == 0:
continue
r = r['items'][0]
if not funny_only:
return r
elif r["likes"]["count"] > FUNNY_THRESHOLD:
return r