Skip to content

Instantly share code, notes, and snippets.

@HirbodBehnam
Last active July 12, 2020 12:07
Show Gist options
  • Save HirbodBehnam/08626322ae4ca0ee360fdb62c3a71d35 to your computer and use it in GitHub Desktop.
Save HirbodBehnam/08626322ae4ca0ee360fdb62c3a71d35 to your computer and use it in GitHub Desktop.
A script to upload file to telegram
# Use the app like python3 TelegramUploader.py /path/to/file
# At first install Telethon and humanize with pip3 install telethon humanize cryptg
# Note that cryptg is optional and only is used for speeding up the uploads
import sys, humanize
from telethon import TelegramClient, events, sync
def upload_progress_callback(downloaded_bytes, total_bytes):
print("Uploaded: " + humanize.naturalsize(downloaded_bytes) + " / " + humanize.naturalsize(total_bytes), end='\r')
# These example values won't work. You must get your own api_id and
# api_hash from https://my.telegram.org, under API Development.
api_id = 12345
api_hash = '0123456789abcdef0123456789abcdef'
client = TelegramClient('session_name', api_id, api_hash)
client.start()
client.send_file('me', sys.argv[1], progress_callback=upload_progress_callback)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment