Example #1
0
def get_proxies():
    """
    连接API获取付费的代理IP
    :return: 代理IP
    """
    # 鹏鹏代理池的接口
    # 发送请求获取响应
    pm = ProxyManager()
    return pm.refresh()
Example #2
0
async def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--config-file',
                        '-c',
                        type=str,
                        default='./config.json')

    args = parser.parse_args()
    config_file = args.config_file

    if not os.path.isfile(config_file):
        raise Exception(f'File "{config_file} not fount"')

    with open(args.config_file, 'r', encoding='utf-8') as f:
        config_data = json.load(f)

    # creating bots from config
    bots = [
        CoinBot(config_data['api_id'], config_data['api_hash'],
                config_data['chat_names'], cfg['phone'], cfg['password'])
        for cfg in config_data['clients']
    ]

    proxy_manager = ProxyManager('https://api.telegram.org')

    while True:
        run_tasks = []

        print('run init bots')
        for bot in bots:
            proxy = await proxy_manager.get_proxy()
            await bot.client_init(proxy)
            run_tasks.append(bot.run())

        try:
            # runing all bots
            print('run all bots')
            await asyncio.gather(*run_tasks)
        except Exception as e:
            print(traceback_msg(e))

        await asyncio.sleep(60)