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")
async def lmgtfy(self, ctx, *, term): '''Let me google that for you!''' term = urllib.parse.quote_plus(term) original = f'https://lmgtfy.com/?iie=1&q={term}' try: short = owo.shorten_urls(self.bot.config.owokey, original) except Exception as e: return await ctx.send( f'An error occured so I couldn\'nt shorten the url! `{e}`\n\n<{original}>' ) await ctx.send(f'<{short[0]}>')
# 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) # Shorten URL res = loop.run_until_complete( owo.async_shorten_urls(key, "http://google.com", loop=loop)) print(res)
my_client.shorten_urls(url1, url2) # 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 urls you want to shorten. owo.shorten_urls(API_KEY, url1, url2) # Example output: ["shortened url 1", "shortened url 2"] # It is also possible to toggle verbosity owo.shorten_urls(API_KEY, url1, url2, verbose=True) # Example output: # [ # { # 'base domain 1': 'shortened url 1', # 'base domain 2': 'other shortened url 1' # }, # { # 'base domain 1': 'shortened url 2', # 'base domain 2': 'other shortened url 2'
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")