Разработано приложение
This commit is contained in:
		
							
								
								
									
										1
									
								
								app/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								app/__init__.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | ||||
| from .main import set_online | ||||
							
								
								
									
										41
									
								
								app/main.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								app/main.py
									
									
									
									
									
										Normal file
									
								
							| @ -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
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								config/__init__.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | ||||
| from .main import VK | ||||
							
								
								
									
										14
									
								
								config/main.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								config/main.py
									
									
									
									
									
										Normal file
									
								
							| @ -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
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								main.py
									
									
									
									
									
										Normal file
									
								
							| @ -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
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								requirements.txt
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,2 @@ | ||||
| aiohttp | ||||
| aioschedule | ||||
		Reference in New Issue
	
	Block a user