-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest_scrap.py
More file actions
54 lines (39 loc) · 1.62 KB
/
Copy pathtest_scrap.py
File metadata and controls
54 lines (39 loc) · 1.62 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
46
47
48
49
50
51
52
53
54
#region
# from telethon import TelegramClient
# from config import Config
# import asyncio
# api_id = Config.TELEGRAM_API_ID
# api_hash = Config.TELEGRAM_API_HASH
# client = TelegramClient('anon', api_id, api_hash)
# async def send_message():
# await client.start()
# try:
# # Use a random image from the internet
# image_url = 'https://via.placeholder.com/1024x683.png' # Random placeholder image URL
# caption = "This is a test message with a random image!" # Caption
# # Send the image with the caption as the message
# await client.send_file(Config.TELEGRAM_CHAT_ID, image_url, caption=caption)
# print("Message with image sent successfully!")
# except Exception as e:
# print(f"Error posting to Telegram: {e}")
# await client.disconnect()
# if __name__ == '__main__':
# asyncio.run(send_message())
#endregion
import asyncio
from telegram import Bot
from config import Config
async def post_to_telegram():
bot = Bot(token=Config.TELEGRAM_BOT_TOKEN)
try:
# Use a random image from the internet
image_url = 'https://via.placeholder.com/1024x683.png' # Random placeholder image URL
caption = "This is a test message with a random image!" # Caption
# Send the image with the caption as the message
await bot.send_photo(chat_id=Config.TELEGRAM_CHAT_ID, photo=image_url, caption=caption)
print("Message with image posted successfully!")
except Exception as e:
print(f"Error posting to Telegram: {e}")
if __name__ == '__main__':
asyncio.run(post_to_telegram())
# asyncio.run(post_to_telegram())