diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2015-05-06 06:02:02 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2015-05-06 06:02:02 +0300 |
commit | 0651896fa9dd3afc42f0080c58e7aa97308e9c96 (patch) | |
tree | 20d4f10975b2403a638a2008cb4168ac4bc46454 /api.py | |
download | vk-scripts-0651896fa9dd3afc42f0080c58e7aa97308e9c96.tar.gz vk-scripts-0651896fa9dd3afc42f0080c58e7aa97308e9c96.zip |
initial commit
Diffstat (limited to '')
-rw-r--r-- | api.py | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -0,0 +1,20 @@ +# Copyright 2015 Egor Tensin <Egor.Tensin@gmail.com> +# 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) |