diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2016-02-12 17:48:48 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2016-02-12 17:48:48 +0300 |
commit | 821c29ee73ed1e6aee8881ae7d921bebc6f7a6e3 (patch) | |
tree | 1db7a0bfcce98d23d9b6ca4a4242595ec066d2c7 | |
parent | rename the scripts (diff) | |
download | vk-scripts-821c29ee73ed1e6aee8881ae7d921bebc6f7a6e3.tar.gz vk-scripts-821c29ee73ed1e6aee8881ae7d921bebc6f7a6e3.zip |
refactoring
-rw-r--r-- | api.py | 17 | ||||
-rw-r--r-- | track_status.py | 3 |
2 files changed, 16 insertions, 4 deletions
@@ -81,11 +81,20 @@ class API: def _lang_is_specified(self): return self.lang != Language.DEFAULT - def _call_method(self, method, **kwargs): - get_args = '&'.join(map(lambda k: '{}={}'.format(k, kwargs[k]), kwargs)) + def _format_method_params(self, **kwargs): + params = '&'.join(map(lambda k: '{}={}'.format(k, kwargs[k]), kwargs)) if self._lang_is_specified(): - get_args += '&lang={}'.format(self.lang.value) - url = 'https://api.vk.com/method/{}?{}'.format(method, get_args) + if params: + params += '&' + params += 'lang={}'.format(self.lang) + return params + + def _build_method_url(self, method, **kwargs): + return 'https://api.vk.com/method/{}?{}'.format( + method, self._format_method_params(**kwargs)) + + def _call_method(self, method, **kwargs): + url = self._build_method_url(method, **kwargs) response = json.loads(urllib.request.urlopen(url).read().decode()) if 'response' not in response: raise self.Error(response) diff --git a/track_status.py b/track_status.py index 2c6776e..3268ab3 100644 --- a/track_status.py +++ b/track_status.py @@ -30,6 +30,9 @@ def format_user_went_online(user): def format_user_went_offline(user): return '{} went OFFLINE'.format(format_user(user)) +def user_is_online(user): + logging.info(format_user_is_online(user)) + def user_is_offline(user): logging.info(format_user_is_offline(user)) logging.info(format_user_last_seen(user)) |