small changes to logging and added example config

This commit is contained in:
Aleksey 2024-04-08 18:08:13 +04:00
parent 1b16f5c215
commit ed82071395
Signed by: tea
GPG Key ID: D9C68D34A3CAE37A
2 changed files with 27 additions and 3 deletions

20
bot.py Normal file → Executable file
View File

@ -159,8 +159,14 @@ class ArchiveWalker:
async def fetch_dialogs(self): async def fetch_dialogs(self):
async for dialog in self.client.iter_dialogs(): async for dialog in self.client.iter_dialogs():
self._log.info(dialog.stringify())
self._log.debug(dialog) self._log.debug(dialog)
e = dialog.entity e = dialog.entity
if isinstance(e, types.Channel):
print(f"Channel: id:{e.id} title:'{e.title}'")
elif isinstance(e, types.User):
print(f"User: id:{e.id} name:'{e.first_name} {e.last_name or ''}'")
for src in self.archives: for src in self.archives:
if e.id != src['id']: if e.id != src['id']:
continue continue
@ -169,9 +175,8 @@ class ArchiveWalker:
self._log.debug("dialog %s is not a channel", e.id) self._log.debug("dialog %s is not a channel", e.id)
continue continue
elif src['type'] == 'User' and not isinstance(e, types.User): elif src['type'] == 'User' and not isinstance(e, types.User):
continue
self._log.debug("dialog %s is not a user", e.id) self._log.debug("dialog %s is not a user", e.id)
self._log.info(dialog.stringify()) continue
yield dialog, src yield dialog, src
async def walk(self): async def walk(self):
@ -207,6 +212,15 @@ if __name__ == '__main__':
app_id = cfg['apps'][0]['id'] app_id = cfg['apps'][0]['id']
app_hash = cfg['apps'][0]['hash'] app_hash = cfg['apps'][0]['hash']
log.debug("client id %s hash %s", app_id, app_hash) log.debug("client id %s hash %s", app_id, app_hash)
client = TelegramClient('session0'+str(app_id), app_id, app_hash) client = TelegramClient(
'session0'+str(app_id),
app_id,
app_hash,
system_version="Windows 11",
device_model = "Gentoo",
app_version = "1.0.0",
lang_code = "en",
system_lang_code = "en-US"
)
with client: with client:
client.loop.run_until_complete(main()) client.loop.run_until_complete(main())

10
config.yaml.example Normal file
View File

@ -0,0 +1,10 @@
apps:
- id: 1234567890
hash: 123456780abcdef123456780abcdef
sources:
- id: 123456789
type: User
destdir: ./download
- id: 987654321
type: Channel
destdir: /path/to/downloads