telegraph
telegraph copied to clipboard
How to upload files (images, etc.)
It's not an issue, I just want to share this code
from telegraph import Telegraph, upload
telegraph = Telegraph()
telegraph.create_account(short_name='LetsTry')
def post(title, content):
response = telegraph.create_page(title,
html_content = content)
return 'https://telegra.ph/{}'.format(response['path'])
files = '/Users/vovkapultik/Downloads/52920087_159420908268041_6560105268061929472_n.jpg'
imgpath = upload.upload_file(files)
print(imgpath)
#['/file/02a1613fc106b225b2b74.jpg']
postlink = post('Title', '<img src="/file/02a1613fc106b225b2b74.jpg">')
print(postlink)
imgpath = upload.upload_file(files)[0]['src'] postlink = post('Title', imgpath)
can write like this, bc upload_file() return a list of dicts with src key. (sorry, my english is poor.
Is there a way to upload multiple photos at once? bro