From 0651896fa9dd3afc42f0080c58e7aa97308e9c96 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Wed, 6 May 2015 06:02:02 +0300 Subject: initial commit --- api.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 api.py (limited to 'api.py') diff --git a/api.py b/api.py new file mode 100644 index 0000000..d584c2b --- /dev/null +++ b/api.py @@ -0,0 +1,20 @@ +# Copyright 2015 Egor Tensin +# This file is licensed under the terms of the MIT License. +# See LICENSE.txt for details. + +import json, sys, urllib.request + +def call_method(method_name, **kwargs): + get_args = '&'.join(map(lambda k: '{}={}'.format(k, kwargs[k]), kwargs)) + url = 'https://api.vk.com/method/{}?{}'.format(method_name, get_args) + response = json.loads(urllib.request.urlopen(url).read().decode()) + if 'response' not in response: + print(response, file=sys.stderr) + sys.exit(-1) + return response['response'] + +def users_get(**kwargs): + return call_method('users.get', **kwargs) + +def friends_get(**kwargs): + return call_method('friends.get', **kwargs) -- cgit v1.2.3