-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
45 lines (36 loc) · 1.47 KB
/
Copy pathmain.py
File metadata and controls
45 lines (36 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from os import getenv
from asyncio import sleep
from dotenv import load_dotenv
from itd import ITDClient, Posts
from itd.logger import setup_logging, get_logger
from itd.enums import AttachType
from telethon import TelegramClient
load_dotenv()
setup_logging()
l = get_logger('itdposts')
ITDClient(getenv('TOKEN'))
client = TelegramClient('session', int(getenv('API_ID', 0)), getenv('API_HASH', ''))
async def main():
while True:
for post in Posts():
l.info('post %s', post.content)
post.view()
attachments = []
for attachment in post.attachments:
path = f'files/{attachment.id}.{"jpg" if attachment.type == AttachType.IMAGE else "mp4" if attachment.type == AttachType.VIDEO else "mp3"}'
attachments.append(path)
attachment.download(path)
await client.send_message(
-1003900304341,
f'''
{post.author.avatar} [{post.author.display_name}](https://xn--d1ah4a.com/@{post.author.username})
{post.content}
❤️{post.likes_count} 🔁{post.reposts_count} 💬{post.comments_count} 👁️{post.views_count}
🔗 [Ссылка на пост]({post.url}) @itdposts
''',
file=attachments if attachments else None, # pyright: ignore[reportArgumentType]
parse_mode='markdown'
)
await sleep(15)
with client: # pyright: ignore[reportGeneralTypeIssues]
client.loop.run_until_complete(main())