Skip to content

Instantly share code, notes, and snippets.

@subtra3t
Created February 26, 2021 11:47
Show Gist options
  • Select an option

  • Save subtra3t/b6e79ae854f56a79f7ecb927752905d2 to your computer and use it in GitHub Desktop.

Select an option

Save subtra3t/b6e79ae854f56a79f7ecb927752905d2 to your computer and use it in GitHub Desktop.

Revisions

  1. subtra3t created this gist Feb 26, 2021.
    22 changes: 22 additions & 0 deletions urlgd.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    import urllib.request


    def create(url, format="simple", logstats=False):
    ascii_url = ""
    for c in url:
    if c in "1234567890qwertyuiopasdfghjklzxcvbnm.":
    ascii_url += c
    else:
    ascii_url += "%" + str(int(str(ord(c)), 16))

    query_params = f"?format={format}&url={url}&logstats={1 if logstats else 0}"

    # Because unfortunately is.gd doesn't trust `Python-urllib/{your python version}`, though they have an API
    user_agent = {
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64)",
    }

    request = urllib.request.Request("https://is.gd/create.php" + query_params, None, user_agent)

    with urllib.request.urlopen(request) as response:
    return response.read().decode("utf-8")