Exemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("key", help="Your API key")
    parser.add_argument("target", help="File to upload/URL to shorten")
    group = parser.add_mutually_exclusive_group()
    group.add_argument("-v",
                       "--verbose",
                       help="Return all domains",
                       action="store_true",
                       default=False)
    group.add_argument("-u", "--url", help="Custom Base url", default=None)
    group = parser.add_mutually_exclusive_group()
    group.add_argument("--upload", help="Upload a file", action="store_true")
    group.add_argument("--shorten", help="Shorten a URL", action="store_true")

    args = parser.parse_args()

    get_verbose = args.verbose or args.url or False

    if args.upload:
        res = owo.upload_files(args.key, args.target, verbose=get_verbose)
        if args.url:
            print(res[args.target.lower()][args.url])
        else:
            print(res[args.target.lower()])

    elif args.shorten:
        res = owo.shorten_urls(args.key, args.target, verbose=get_verbose)
        if args.url:
            print(res[0][args.url])
        else:
            print(res[0])

    else:
        parser.error("Either --upload or --shorten should be given")
Exemplo n.º 2
0
# Required Imports
import owo

# Asynchronous Only Imports
import asyncio

# Optional Import for Making a Byte Stream
from io import BytesIO

# ############################################################

key = input("Please enter your API key: ")

# Upload Image
res = owo.upload_files(key, "example.png")
print(res)

# Shorten URL
res = owo.shorten_urls(key, "http://google.com")
print(res)

# ############################################################

loop = asyncio.get_event_loop()

# Upload Image
res = loop.run_until_complete(
    owo.async_upload_files(key, "example.png", loop=loop))
print(res)
Exemplo n.º 3
0
my_client.upload_files("example.png", "example.txt")

# The client also stores verbosity (default: False), which can be toggled using
# Client.toggle_verbose()
# Verbosity should be given using a kwarg to __init__, i.e.

my_client = owo.Client(API_KEY, verbose=True)
my_client.toggle_verbose()
my_client.verbose  # False

# ############################################################

# NON ASYNCHRONOUS EXAMPLES

# Specify which files that you would like to upload.
owo.upload_files(API_KEY, "example.png", "example.txt")

# Example output: {"example.png": "url", "example.txt": "url"}

# It is also possible to toggle verbosity
owo.upload_files(API_KEY, "example.png", "example.txt", verbose=True)

# Example output:
# {
#     'example.png': {'base domain 1': 'url 1', 'base domain 2': 'other url 1'},
#     'example.txt': {'base domain 1': 'url 2', 'base domain 2': 'other url 2'}
# }

# ############################################################

# ASYNCHRONOUS EXAMPLES
Exemplo n.º 4
0
import argparse
import owo

parser = argparse.ArgumentParser()
parser.add_argument("key", help="Your API key")
parser.add_argument("target", help="File to upload/URL to shorten")
parser.add_argument("-v",
                    "--verbose",
                    help="Return all domains",
                    action="store_true",
                    default=False)
group = parser.add_mutually_exclusive_group()
group.add_argument("--upload", help="Upload a file", action="store_true")
group.add_argument("--shorten", help="Shorten a URL", action="store_true")

args = parser.parse_args()

if args.upload:
    res = owo.upload_files(args.key, args.target, verbose=args.verbose)
    print(res[args.target])

elif args.shorten:
    res = owo.shorten_urls(args.key, args.target, verbose=args.verbose)
    print(res[0])

else:
    parser.error("Either --upload or --shorten should be given")
Exemplo n.º 5
0
def main():
    if not args.path.endswith("/"):
        args.path += "/"

    print("Starting background process...")
    while True:
        time.sleep(2)
        new_files = [
            f for f in os.listdir(args.path)
            if f not in sent_files and os.path.isfile(args.path + f)
        ]
        if new_files == []:
            continue
        for file in new_files:
            print_v("Found file: {}".format(file))
            try:
                urls = list(
                    owo.upload_files(args.key, args.path + file,
                                     verbose=True).values())[0]

                url = urls.get(args.url)
                if url is None:
                    print("Vanity url base {} was not found, using default".
                          format(args.url))
                    url = urls["https://owo.whats-th.is/"]

            except ValueError as e:
                print("Upload failed:\n{}".format(e.args[0]))

                # For this we can just use try:except
                try:
                    if args.tts:
                        os.system('termux-tts-speak "Upload failed"')
                    else:
                        os.system('termux-toast "Upload failed"')
                except FileNotFoundError:
                    pass

            except OverflowError:
                print("File too big: {}".format(file))

                # For this we can just use try:except
                try:
                    if args.tts:
                        os.system('termux-tts-speak "Upload too big"')
                    else:
                        os.system('termux-toast "Upload too big"')
                except FileNotFoundError:
                    pass
                sent_files.append(file)

            else:
                print_v("Upload successful.")
                sent_files.append(file)
                if (sys.executable ==
                        "/data/data/com.termux/files/usr/bin/python"):
                    # Mobile devices

                    try:
                        # os.system won't raise an error
                        subprocess.run(
                            shlex.split(
                                ("termux-notification "
                                 '--title "File uploaded" '
                                 '--content "{0}" '
                                 '--button1 "Copy link" '
                                 '--button1-action "termux-clipboard-set {0}" '
                                 '--button2 "Share" '
                                 '--button2-action "termux-open \"{0}\"" '
                                 ).format(url)))

                        if args.tts:
                            # We don't need a try:catch for this
                            os.system('termux-tts-speak "Upload success"')
                        else:
                            os.system('termux-toast "Upload success"')

                        print_v("Sent notification")
                    except FileNotFoundError:
                        # termux-api not installed
                        print("File uploaded: {}, URL: {}".format(file, url))
                else:
                    # Non-mobile devices
                    print("File uploaded: {}, URL: {}".format(file, url))