Skip to content

Commit

Permalink
Image upload more standalone
Browse files Browse the repository at this point in the history
  • Loading branch information
Yolk committed Jan 16, 2017
1 parent 3b78708 commit ae1a45c
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions html_telegraph_poster/upload_images.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
import mimetypes
import re
import requests
from html_telegraph_poster.html_to_telegraph import default_user_agent
from .errors import *

from io import BytesIO
base_url = 'https://telegra.ph'
save_url = 'https://edit.telegra.ph/save'
upload_file_url = 'http://telegra.ph/upload'


class Error(Exception):
pass


class GetImageRequestError(Error):
pass


class ImageUploadHTTPError(Error):
pass


class FileTypeNotSupported(Error):
pass


def _check_mimetypes(type):
return type in ['image/jpeg', 'image/png', 'image/gif', 'video/mp4']


def upload_image(file_name_or_url, user_agent=default_user_agent):
def upload_image(file_name_or_url, user_agent='Python_telegraph_poster/0.1'):

if re.match(r'^https?://', file_name_or_url, flags=re.IGNORECASE):
img = requests.get(file_name_or_url, headers={'User-Agent': user_agent})
Expand Down

0 comments on commit ae1a45c

Please sign in to comment.