mirror of
https://github.com/tiennm99/export-telegram-group-members.git
synced 2026-10-11 03:13:26 +00:00
feat(config): prompt for setup values
This commit is contained in:
1 parent
3d655ea020
commit
10298f4f5e
2 files changed
+44
-11
No files matched your search
@@ -22,10 +22,10 @@ pip install -r requirements.txt
|
||||
6. Store Telegram config in Redis:
|
||||
|
||||
```bash
|
||||
python configure.py --api-id <api_id> --phone <phone> --groups <group_id1>,<group_id2>
|
||||
python configure.py
|
||||
```
|
||||
|
||||
`configure.py` prompts for `api_hash` so it does not land in shell history.
|
||||
`configure.py` prompts for `api_id`, `api_hash`, phone, and group IDs.
|
||||
|
||||
7. Crawl configured groups:
|
||||
|
||||
|
||||
+42
-9
@@ -6,34 +6,67 @@ def parse_args():
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Store Telegram crawl config in Redis.',
|
||||
)
|
||||
parser.add_argument('--api-id', required=True, type=int, help='Telegram API ID')
|
||||
parser.add_argument('--api-id', type=int, help='Telegram API ID')
|
||||
parser.add_argument('--api-hash', help='Telegram API hash')
|
||||
parser.add_argument('--phone', required=True, help='Telegram account phone')
|
||||
parser.add_argument('--phone', help='Telegram account phone')
|
||||
parser.add_argument(
|
||||
'--groups',
|
||||
required=True,
|
||||
help='Comma-separated Telegram group IDs to crawl',
|
||||
)
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def prompt_required(label):
|
||||
value = input(f'{label}: ').strip()
|
||||
if not value:
|
||||
raise SystemExit(f'{label.lower()} is required')
|
||||
return value
|
||||
|
||||
|
||||
def prompt_api_id(value):
|
||||
if value is not None:
|
||||
return value
|
||||
try:
|
||||
return int(prompt_required('API ID'))
|
||||
except ValueError as exc:
|
||||
raise SystemExit('api id must be an integer') from exc
|
||||
|
||||
|
||||
def prompt_api_hash(value):
|
||||
api_hash = value or getpass.getpass('API hash: ')
|
||||
if not api_hash:
|
||||
raise SystemExit('api hash is required')
|
||||
return api_hash
|
||||
|
||||
|
||||
def prompt_phone(value):
|
||||
return value or prompt_required('Phone')
|
||||
|
||||
|
||||
def prompt_groups(value):
|
||||
return parse_group_ids(value or prompt_required('Group IDs'))
|
||||
|
||||
|
||||
def parse_group_ids(value):
|
||||
group_ids = [part.strip() for part in value.split(',') if part.strip()]
|
||||
if not group_ids:
|
||||
raise SystemExit('at least one group id is required')
|
||||
return [int(group_id) for group_id in group_ids]
|
||||
try:
|
||||
return [int(group_id) for group_id in group_ids]
|
||||
except ValueError as exc:
|
||||
raise SystemExit('group ids must be comma-separated integers') from exc
|
||||
|
||||
|
||||
def main():
|
||||
args = parse_args()
|
||||
group_ids = parse_group_ids(args.groups)
|
||||
api_hash = args.api_hash or getpass.getpass('API hash: ')
|
||||
if not api_hash:
|
||||
raise SystemExit('api hash is required')
|
||||
api_id = prompt_api_id(args.api_id)
|
||||
api_hash = prompt_api_hash(args.api_hash)
|
||||
phone = prompt_phone(args.phone)
|
||||
group_ids = prompt_groups(args.groups)
|
||||
|
||||
from config import save_app_config
|
||||
|
||||
config = save_app_config(args.api_id, api_hash, args.phone, group_ids)
|
||||
config = save_app_config(api_id, api_hash, phone, group_ids)
|
||||
print(f'saved Redis config for {config["phone"]}: {len(group_ids)} group(s).')
|
||||
return 0
|
||||
|
||||
|
||||
Reference in new issue
Block a user