Skip to content

Instantly share code, notes, and snippets.

@anir0y
Created November 13, 2022 13:17
Show Gist options
  • Save anir0y/5d7c8b6460da82134eef86dbb61af891 to your computer and use it in GitHub Desktop.
Save anir0y/5d7c8b6460da82134eef86dbb61af891 to your computer and use it in GitHub Desktop.
Script to create short URL using tiny.url API
import json
import requests
banner="""
=^..^=
==> created by @anir0y
[+] we use tinyurl to create short URL
[+] reach me twitter: @anir0y
"""
print(banner)
inputurl=input("Enter Long URl and we will short it out: ")
headers = {
'accept': 'application/json',
# Already added when you pass json= but not when you pass data=
# 'Content-Type': 'application/json',
}
params = {
'api_token': 'YOUR_TOKEN_HERE',
}
json_data = {
'url': inputurl,
'domain': 'tiny.one', # you can change it to your domain(paid/free)
}
response = requests.post('https://api.tinyurl.com/create', params=params, headers=headers, json=json_data)
# parsing output
response = (response.text)
jsonblob= json.loads(response)
tinyurl=(jsonblob['data']['tiny_url'])
fullurl=(jsonblob['data']['url'])
# print output
print(banner)
print (f"Hey, your Long Boi URL: {fullurl}")
print (f" now shortboi url {tinyurl}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment