Python: Merge Multiple PDFs into One
Merge several PDF files into one with Python in a few lines — keep the page order you choose.
Send yourself a Telegram message from Python — free alerts for scripts, servers and price trackers.
16 lines · Updated Nov 26, 2026
import os
import requests
def send_telegram(message):
token = os.environ["TELEGRAM_BOT_TOKEN"]
chat_id = os.environ["TELEGRAM_CHAT_ID"]
url = f"https://api.telegram.org/bot{token}/sendMessage"
response = requests.post(url, json={
"chat_id": chat_id,
"text": message,
}, timeout=15)
response.raise_for_status()
return response.json()
if __name__ == "__main__":
send_telegram("Price alert: the laptop dropped to Rs 145,000!")
Telegram bots are the easiest way to get instant notifications on your phone from any script: a backup finished, a price dropped, a server went down, a new order arrived. This snippet sends a message through the Telegram Bot API with a single HTTP request in Python — no special library needed.
sendMessage method with the chat ID and the text, and checks the response./newbot and follow the steps to get your token.https://api.telegram.org/bot<TOKEN>/getUpdates in a browser and copy the chat.id value.parse_mode HTML or Markdown for bold text and links.Anyone with the token controls your bot. Never commit it to GitHub — keep it in an environment variable, and revoke it in BotFather if it leaks.
Related: Website change monitor · Retry with backoff
Create a bot with @BotFather on Telegram, start a chat with it, and get your chat id. Set TELEGRAM_BOT_TOKEN and TELEGRAM_CHAT_ID as environment variables — never hard-code the token.
Share this snippet
Merge several PDF files into one with Python in a few lines — keep the page order you choose.
Read the text out of any PDF with Python — the first step for search, summaries and automation.
Generate a strong random password with Python using the secrets module — never use random() for passwords.