#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
Transform urls into temporary files

Usage: unurl [-h] [-n name] [URL]

Argument:
    URL     URL to download

Options:
    -h, --help          Print this help and exit.
    -n, --name name     Use `name' as the temporary file name.
"""

import time
from docopt import docopt

def main():
    args = docopt(__doc__)
    url  = args["URL"]
    name = args["--name"] or "tmp_unurl"
    path = "/tmp/" + name

    if not url:
        print(path)
        return

    if '://' not in url:
        print(url)

    else:
        import requests
        r = requests.get(url)
        with open(path, "wb") as f:
            f.write(r.content)
        print(path)

if __name__ == "__main__":
    main()
