Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import time
import requests
import json
last_call = 0
def vk_query(method, **kwargs):
global last_call
ct = time.time()
if ct - last_call < 0.34:
time.sleep(0.34 - ct + last_call)
last_call = ct
url = 'https://api.vk.com/method/{}?v=5.60'.format(method)
for key, value in kwargs.iteritems():
url += '&{}={}'.format(key, value)
body = requests.get(url).content
try:
res = json.loads(body)['response']
except KeyError:
print "Failed to execute query", url
print "Result"
print body
return
except RuntimeError as e:
print "Failed to execute query", url
print "Result"
print body
raise e
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.