Skip to content

Commit 9290d99

Browse files
committed
Added a URL Shortener
1 parent fdc27a9 commit 9290d99

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

URL Shortener/urlshortener.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import requests
2+
3+
def shorten_url_with_tinyurl(long_url):
4+
url = f'http://tinyurl.com/api-create.php?url={long_url}'
5+
response = requests.get(url)
6+
if response.status_code == 200:
7+
return response.text
8+
else:
9+
return None
10+
11+
long_url = r"INSERT YOUR LONG URL HERE"
12+
short_url = shorten_url_with_tinyurl(long_url)
13+
14+
if short_url:
15+
print(f'Shortened URL: {short_url}')
16+
else:
17+
print('Error shortening URL')

0 commit comments

Comments
 (0)