Example #1
0
def async_callback_download(path, ext, receiver):
    if path is None:
        return
    mimetype, _ = mimetypes.guess_type(path)
    if not mimetype:
        return
    mime = mimetype.split('/')[0]
    f = tgl.send_file
    if ext == "gif" or ext == "webp" or mime == "text":
        f = tgl.send_document
    elif mime == "image":
        f = tgl.send_image
    elif mime == "audio":
        f = tgl.send_audio
    elif mime == "video":
        f = tgl.send_video
        print("Sending file with mime {} from path {}".format(mimetype, path))
    f(receiver, path, utils.cb_rmp(path))
Example #2
0
def synchronous(url, ext, receiver):
    path = ''
    try:
        path = utils.download_to_file(url, ext)
    except:
        print("Error downloading {}".format(url))
        return
    mimetype, _ = mimetypes.guess_type(path)
    if not mimetype:
        return
    mime = mimetype.split('/')[0]
    f = tgl.send_file
    if ext == "gif" or ext == "webp" or mime == "text":
        f = tgl.send_document
    elif mime == "image":
        f = tgl.send_image
    elif mime == "audio":
        f = tgl.send_audio
    elif mime == "video":
        f = tgl.send_video
    print("Sending file with mime {} from path {}".format(mimetype, path))
    f(receiver, path, utils.cb_rmp(path))