Хочу разместить телеграмм бота на облаке selectel. Как переделать данного бота чтобы он подходил под serverless архитектуру?
import asyncio
import logging
import os
import config
import requests
import json
from aiogram import Bot, Dispatcher, executor, types
logging.basicConfig(level=logging.INFO)
bot = Bot(token=config.TOKEN)
dp = Dispatcher(bot)
async def on_startup():
namebot = 'bot'
while namebot == 'bot':
try:
with open('id.txt', 'r') as f:
last = f.read()
url = 'https://affise.com/3.0/admin/partner/' + str(last) + '?API-Key=APIKEY'
answer = requests.get(url)
parsed_string = json.loads(answer.text)
if parsed_string['status'] == 1:
if int(parsed_string['partner']['id']) >= int(last):
id_t = parsed_string['partner']['id']
email_t = parsed_string['partner']['email']
telegram_t = parsed_string['partner']['customFields'][0]['value']
requests.post('https://affise.com/3.0/admin/partner/' + str(id_t)+ '?API-Key=APIKEY',
data={'manager_id': '617686d4020a29de3781d', 'status': 'active'})
manager_t = 'Aff Manager'
message_out = 'Зарегистрирован новый партнер: \nID: ' + str(
id_t) + '\n' + 'Email: ' + email_t + '\n' \
+ 'Telegram: ' + telegram_t + '\n' + 'Менеджер: ' + manager_t + '\n '
await bot.send_message(chat_id='-10016813475', text=message_out)
last2 = int(last) + 1
new_data = last.replace(last, str(last2))
with open('id.txt', 'w') as f:
f.write(new_data)
except Exception as e:
print('Ошибка: ' + repr(e))
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.create_task(on_startup())
executor.start_polling(dp, skip_updates=True)