Skip to content

Instantly share code, notes, and snippets.

@subtra3t
Created February 26, 2021 11:47
Show Gist options
  • Save subtra3t/b6e79ae854f56a79f7ecb927752905d2 to your computer and use it in GitHub Desktop.
Save subtra3t/b6e79ae854f56a79f7ecb927752905d2 to your computer and use it in GitHub Desktop.
is.gd python
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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment