text = '5 мин' if frame == 5 else '1 час' _frames.append((frame, text)) db.close() return sorted(_names), _frames, client, folder_id logging = [] idMe = 396978030 db_path = 'db/database.db' objects.environmental_files() os.makedirs('db', exist_ok=True) os.makedirs('images', exist_ok=True) Auth = objects.AuthCentre(LOG_DELAY=15, ID_DEV=-1001312302092, ID_DUMP=-1001486338288, ID_LOGS=-1001275893652, ID_MEDIA=-1001423966952, ID_FORWARD=-1001254536149, TOKEN=os.environ.get('TOKEN'), DEV_TOKEN=os.environ['DEV_TOKEN']) download_alt_image() bot = Auth.async_bot dispatcher = Dispatcher(bot) names, frames, drive_client, main_folder = images_db_creation() zero_user, google_users_ids, users_columns = users_db_creation() # ================================================================================================================= keys = Keys() def first_start(message): db = SQL(db_path)
except Exception as e: search_exception = re.search('You can\'t delete all the rows on the sheet', str(e)) if search_exception: values = data5.update_cell(1, 1, '') else: values = None sleep(3) else: values = None sleep(1) return values start_search = objects.query('https://t.me/UsefullCWLinks/' + str(start_link), 'd: (.*) :d') used_array = google('moscow-growing', 'col_values', 1) Auth = objects.AuthCentre(os.environ['TOKEN']) bot = Auth.start_main_bot('non-sync') executive = Auth.thread_exec if start_search: last_date = stamper(start_search.group(1)) - 3 * 60 * 60 Auth.start_message(stamp1) else: last_date = '\nОшибка с нахождением номера поста. ' + bold('Бот выключен') Auth.start_message(stamp1, last_date) _thread.exit() # ==================================================================================== def hour(): return int(datetime.utcfromtimestamp(objects.time_now() + 3 * 60 * 60).strftime('%H'))
db.close() return _zero_user, ['id', *users_ids], columns logging = [] idMe = 396978030 start_message = None db_path = 'db/database.db' objects.environmental_files() loop = asyncio.get_event_loop() os.makedirs('db', exist_ok=True) tz = timezone(timedelta(hours=3)) Auth = objects.AuthCentre(LOG_DELAY=120, ID_DEV=-1001312302092, TOKEN=os.environ.get('TOKEN'), ID_DUMP=os.environ.get('ID_DUMP'), ID_LOGS=os.environ.get('ID_LOGS'), ID_MEDIA=os.environ.get('ID_MEDIA'), DEV_TOKEN=os.environ.get('DEV_TOKEN'), ID_FORWARD=os.environ.get('ID_FORWARD')) bot = Auth.async_bot dispatcher = Dispatcher(bot) digest_channel = os.environ['ID_DIGEST'] zero_user, google_users_ids, users_columns = users_db_creation() channels = [ os.environ.get(key) for key in ['ID_DUMP', 'ID_MEDIA', 'ID_FORWARD', 'ID_DIGEST'] ] channels.extend([*os.environ.get('ID_LOGS').split(' '), str(Auth.dev.chat_id)]) # =================================================================================================================
def multiple_requests(self, active_array, full_limit, max_workers=10): stuck = 0 loop = True ranges = [] response = {} used_array = [] temp_ranges = [] update_array = [] request_array = [] prev_update_array = [] limit = copy(full_limit) for post_id in active_array: ranges.extend(range(post_id - 10, post_id + 11)) for post_id in dict( sorted(Counter(ranges).items(), key=lambda item: item[1], reverse=True)): if post_id not in temp_ranges and post_id in active_array: temp_ranges.extend(range(post_id - 10, post_id + 11)) request_array.append(post_id) delay = len(request_array) / 5 delay = int(delay + 1 if delay.is_integer() is False else delay) while loop is True: links = [] if len(update_array) == 0: for lot_id in request_array: if len(update_array ) < full_limit and lot_id not in used_array: update_array.append(lot_id) used_array.append(lot_id) else: if update_array == prev_update_array: stuck += 1 else: prev_update_array = deepcopy(update_array) stuck = 0 if stuck in [50, 500, 5000]: auth = objects.AuthCentre(os.environ['ERROR-TOKEN']) message = f"active_array({len(active_array)}) = {active_array}\n" \ f"request_array({len(request_array)}) = {request_array}\n" \ f"update_array({len(update_array)}) = {update_array}\n" \ f"delay = {delay}" auth.send_json(message, 'variables', 'Бесконечный цикл обновляющихся лотов') for lot_id in update_array: links.append(f"{self.server['link: channel']}{lot_id}") limit -= 1 temp_array = deepcopy(update_array) print_text, stamp = f"{len(links)}: ", datetime.now().timestamp() with concurrent.futures.ThreadPoolExecutor( max_workers=max_workers) as future_executor: futures = [ future_executor.submit(requests.get, future) for future in links ] for future in concurrent.futures.as_completed(futures): result = self.former(future.result(), active_array) response.update(result) for lot_id in result: if lot_id in temp_array: temp_array[temp_array.index(lot_id)] = None update_array = [] objects.printer( f"{print_text}{datetime.now().timestamp() - stamp}") for lot_id in temp_array: if lot_id is not None: update_array.append(lot_id) if len(update_array) == 0 and len(used_array) == len( request_array): loop = False if limit <= 0: limit = copy(full_limit) delay -= 60 sleep(60) return 0 if delay < 0 else delay, list(response.values())
import re import asyncio import objects import secrets import requests import concurrent.futures from aiogram import types from bs4 import BeautifulSoup from aiogram.utils import executor from aiogram.dispatcher import Dispatcher from aiogram.types import InlineQueryResultArticle as Article from aiogram.types import InlineQuery, InputTextMessageContent # ======================================================================================================== stamp1 = objects.time_now() Auth = objects.AuthCentre(ID_DEV=-1001312302092, TOKEN=os.environ['TOKEN'], DEV_TOKEN=os.environ['DEV_TOKEN']) bot, idMe, t_me, dispatcher = Auth.async_bot, 396978030, 'https://t.me/', Dispatcher(Auth.async_bot) # ======================================================================================================== if os.environ.get('local') is None: Auth.dev.start(stamp1) def rand(): return secrets.token_hex(20) @dispatcher.message_handler() async def repeat_all_messages(message: types.Message): try: if message['chat']['id'] == idMe:
start_post = 8 unused_box = [] idMe = 396978030 color = (0, 0, 0) idAndre = 470292601 keyboard.add(*buttons) idMain = -1001404073893 idJobi = -1001272631426 idTikTok = -1001498374657 idInstagram = -1001186786378 start_address = 'https://t.me/UsefullCWLinks/' + str(start_post) # ================================================================= start_search = objects.query(start_address + '?embed=1', 'd: (.*?) :d.block: (.*?) :block') ExceptAuth = objects.AuthCentre(os.environ['TOKEN'], idMe) Auth = objects.AuthCentre(os.environ['TOKEN']) bot = Auth.start_main_bot('non-async') executive = ExceptAuth.thread_exec if start_search: last_date = objects.stamper(start_search.group(1)) - 3 * 60 * 60 block = start_search.group(2) Auth.start_message(stamp1) else: last_date = '\nОшибка с нахождением номера поста. ' + bold('Бот выключен') Auth.start_message(stamp1, last_date) block = 'False' _thread.exit() # ====================================================================================
import os import objects from api import ChatWars stamp1 = objects.time_now() cw = ChatWars(os.environ['LOGIN'], os.environ['PASS']) objects.AuthCentre(os.environ['TOKEN']).start_message(stamp1) def api_handler(): global cw while True: try: cw.run() # this blocks execution except KeyboardInterrupt: cw.stop() if __name__ == '__main__': api_handler()