Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
main.py added
Browse files Browse the repository at this point in the history
  • Loading branch information
hhhscvx committed Sep 23, 2024
1 parent e500cda commit 2495e17
Showing 1 changed file with 46 additions and 15 deletions.
61 changes: 46 additions & 15 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import argparse
import asyncio
import os
from itertools import zip_longest

from pyrogram import Client

from data import config
from utils.banana import Banana
from utils.core.file_manager import get_all_lines
from utils.core.telegram import Accounts
from utils.starter import start


async def main():
async def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("-a", "--action", type=int, help="Action to perform")

action = parser.parse_args().action
if not action:
action = int(input("Select action:\n1. Start soft\n2. Create sessions\n\n> "))

if not os.path.exists('sessions'):
os.mkdir('sessions')

Expand All @@ -21,22 +32,42 @@ async def main():
with open("sessions/accounts.json", 'w') as f:
f.write("[]")

# await Accounts().create_sessions()
if action == 2:
await Accounts().create_sessions()

if action == 1:
accounts = await Accounts().get_accounts()

tasks = []

if config.USE_PROXY_FROM_FILE:
proxys = get_all_lines(filepath=config.PROXY_PATH)
for account, proxy in zip_longest(accounts, proxys):
if not account:
break
_, _, proxy = account.values()
client = get_client_by_account(account)
tasks.append(asyncio.create_task(start(tg_client=client, proxy=proxy)))
else:
for account in accounts:
_, _, proxy = account.values()
client = get_client_by_account(account)
tasks.append(asyncio.create_task(start(tg_client=client, proxy=proxy)))

await asyncio.gather(*tasks)

accounts = await Accounts().get_accounts()

for account in accounts:
session_name, phone_number, _ = account.values()
client = Client(
name=session_name,
api_id=config.API_ID,
api_hash=config.API_HASH,
phone_number=phone_number,
workdir=config.WORKDIR
)
def get_client_by_account(account: dict) -> Client:
session_name, _, proxy = account.values()

return Client(
name=session_name,
api_id=config.API_ID,
api_hash=config.API_HASH,
proxy=proxy,
workdir=config.WORKDIR
)

banana = Banana(tg_client=client)
await banana.get_tg_web_data()

if __name__ == "__main__":
asyncio.run(main())
asyncio.get_event_loop().run_until_complete(main())

0 comments on commit 2495e17

Please sign in to comment.