Разработано приложение
Этот коммит содержится в:
Коммит
5a3bfed451
1
app/__init__.py
Обычный файл
1
app/__init__.py
Обычный файл
@ -0,0 +1 @@
|
|||||||
|
from .main import set_online
|
41
app/main.py
Обычный файл
41
app/main.py
Обычный файл
@ -0,0 +1,41 @@
|
|||||||
|
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())
|
1
config/__init__.py
Обычный файл
1
config/__init__.py
Обычный файл
@ -0,0 +1 @@
|
|||||||
|
from .main import VK
|
14
config/main.py
Обычный файл
14
config/main.py
Обычный файл
@ -0,0 +1,14 @@
|
|||||||
|
from configparser import RawConfigParser
|
||||||
|
|
||||||
|
|
||||||
|
config = RawConfigParser()
|
||||||
|
config.read(
|
||||||
|
filenames='./config.ini',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class VK:
|
||||||
|
access_token = config.get(
|
||||||
|
section='VK',
|
||||||
|
option='access_token',
|
||||||
|
)
|
14
main.py
Обычный файл
14
main.py
Обычный файл
@ -0,0 +1,14 @@
|
|||||||
|
import asyncio
|
||||||
|
import time
|
||||||
|
|
||||||
|
import aioschedule
|
||||||
|
|
||||||
|
from app import set_online
|
||||||
|
|
||||||
|
|
||||||
|
aioschedule.every(60 * 2).to(60 * 5).seconds.do(set_online)
|
||||||
|
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
while True:
|
||||||
|
loop.run_until_complete(aioschedule.run_pending())
|
||||||
|
time.sleep(.1)
|
2
requirements.txt
Обычный файл
2
requirements.txt
Обычный файл
@ -0,0 +1,2 @@
|
|||||||
|
aiohttp
|
||||||
|
aioschedule
|
Загрузка…
Ссылка в новой задаче
Block a user