Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save artemrys/4e07476300d85f80100a3e6993187bf7 to your computer and use it in GitHub Desktop.
Save artemrys/4e07476300d85f80100a3e6993187bf7 to your computer and use it in GitHub Desktop.
Save file from Unsplash and send it to Telegram bot
import requests
import os
r = requests.get("https://images.unsplash.com/photo-1452857576997-f0f12cd77844?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2850&q=80")
with open("photo.jpg", "wb") as f:
f.write(r.content)
requests.post(
"https://api.telegram.org/bot<TOKEN>/sendPhoto?chat_id=<chat_id>",
files={"photo": open("photo.jpg", "rb")}
)
os.remove("photo.jpg")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment