42 строки
1.1 KiB
Python
42 строки
1.1 KiB
Python
|
import json
|
||
|
import logging
|
||
|
import traceback
|
||
|
from urllib.parse import ParseResult, urlparse, urlencode
|
||
|
|
||
|
import aiohttp
|
||
|
|
||
|
import config
|
||
|
|
||
|
|
||
|
logging.basicConfig(
|
||
|
level=logging.ERROR,
|
||
|
)
|
||
|
logger = logging.getLogger()
|
||
|
|
||
|
set_online_url = urlparse('https://api.vk.com/method/account.setOnline')
|
||
|
|
||
|
|
||
|
async def set_online():
|
||
|
try:
|
||
|
query = {
|
||
|
'access_token': config.VK.access_token,
|
||
|
'voip': '0',
|
||
|
'v': '5.154',
|
||
|
}
|
||
|
url = ParseResult(
|
||
|
scheme=set_online_url.scheme,
|
||
|
netloc=set_online_url.hostname,
|
||
|
path=set_online_url.path,
|
||
|
params=set_online_url.params,
|
||
|
query=urlencode(query),
|
||
|
fragment=set_online_url.fragment,
|
||
|
)
|
||
|
async with aiohttp.ClientSession() as session:
|
||
|
async with session.get(url.geturl()) as response:
|
||
|
assert response.status == 200
|
||
|
assert json.loads(await response.read()).get('response') == 1
|
||
|
except AssertionError:
|
||
|
logger.error(traceback.format_exc())
|
||
|
except Exception:
|
||
|
logger.critical(traceback.format_exc())
|