async def async_main(): cursor1 = db.rastreiobot.find() start = time() if check_system(): pass else: print("exit") return # await bot.send_message(str(-340600919), "oi", parse_mode='HTML', # disable_web_page_preview=True) tasks = [] n = 0 async for elem in cursor1: api_type = check_type(elem['code']) if api_type is correios: n += 1 tasks.append(up_package(elem)) await asyncio.gather(*tasks) if __name__ == '__main__': executor.start(dp, async_main()) # ida ao banco # chamada da api # fala com o usuario
async def daily_update() -> None: '''Send each user some stats.''' # TODO: Notify all users for i in range(2): chat_id = 844457200 message = 'meow ' + str(i) await send_message(chat_id, message) async def send_message(chat_id: int, message: str) -> None: '''Send a message to a single user.''' try: await BOT.send_message(chat_id=chat_id, text=message, disable_notification=True) await asyncio.sleep(1.0) # Max 1 message / sec except (exceptions.BotBlocked, exceptions.UserDeactivated, exceptions.ChatNotFound): logging.debug('Target [ID:%s]: Impossible to reach him.', chat_id) except exceptions.TelegramAPIError as exc: logging.exception('Target [ID:%s]: %s.', chat_id, str(exc)) # Send messages executor.start(DP, daily_update())
def send_any_msg(dp, bot, msg): message = msg executor.start(dp, send_message(bot, text=message))
LinkList = [] r = requests.post(url=link) scrapper = BeautifulSoup(r.content, "html.parser") for item in scrapper.find_all('td', class_="left"): for sub_item in item.find_all('a', class_="bigger visitable"): LinkList.append(sub_item.get('href')) reg = re.compile('[^0-9]') dt = reg.sub('', sub_item.get('href')) if dt in Orderd_list: pass else: Orderd_list.append(dt) await self.ParsePost(sub_item.get('href')) bot = Bot(token="your bot token") dp = Dispatcher(bot) async def main(): obt = ParserData() while True: await obt.ParseLinks( "https://freelancehunt.ua/projects/skill/razrabotka-botov/180.html" ) time.sleep(200) if __name__ == '__main__': executor.start(dp, main())
def send_float_order(dp, bot, trend, execQty, avgPrice): message = "CONTINUE: " + trend + '\n' +\ 'TOTAL QTY: ' + execQty + '\n' + \ 'PRICE: ' + avgPrice executor.start(dp, send_message(bot, text=message))
def send_place_order(dp, bot, trend, execQty, avgPrice): message = "PLACED: " + trend + '\n' +\ 'QTY: ' + execQty + '\n' +\ 'PRICE: ' + avgPrice executor.start(dp, send_message(bot, text=message))
def send_pnl(dp, bot, pnl, price): message = "PNL: " + pnl + '\n' + 'PRICE: ' + price executor.start(dp, send_message(bot, text=message))
def send_start(dp, bot): executor.start(dp, send_message(bot, text='START PRINTING NOW' + '\n'))
def run(): executor.start(dp, main())