4 Line python-based URL shortener

I go by theroyakash on the internet. I am a computer scientist, with research in high performance algorithms, data structures, distributed systems, and beyond. See my work searching google for theroyakash.
Let's build an URL shortener with just 4 lines of code. I'll keep it as simple as possible.
Inspiration
I was building a discord BOT that has the feature of sending top news article in a given hour, but the URLs were too long so it was looking bad in a discord chat. So I thought of making an shortener service based on tiny-url to beautify those long a** URLs.
Requirements
contextlibfor utilities for with-statement contexts,- and
urllibmodule which are built-in. So nothing needed to be installed.
Code
import contextlib
from urllib.parse import urlencode
from urllib.request import urlopen
def tinyURLOf(url):
encoded_url = urlencode({'url': url})
request_url = 'http://tinyurl.com/api-create.php?' + str(encoded_url)
with contextlib.closing(urlopen(request_url)) as response:
return response.read().decode('utf-8 ')
So now run the function tinyURLOf(url='YOUR_URL_HERE') to get the result back.


![Set-up an audio version of your blog articles [Works Automatically]](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1612940767582%2F0abS3UT_8.png&w=3840&q=75)

