"""
URL Shortner
26/06/2024
MIT Licence
Author: Aman Babu Hemant
"""
try:
import textual
import requests
except ImportError:
import os
os.system("pip install textual")
os.system("pip install requests")
from textual.app import App
from textual.widgets import Input, Button, Static
from requests import get
class URLShortner(App):
def compose(self):
yield Input(id="long", placeholder="Long URL")
yield Button("Shorten")
yield Input(id="short", disabled=True)
def on_button_pressed(self, e):
long_url = app.query_one("#long").value
if not (long_url.startswith("http://") or
long_url.startswith("https://")
):
return app.notify("URL must starts with https:// or https://")
try:
r = get("https://htmlify.artizote.com/api/shortlink?url="+long_url).json()
s = app.query_one("#short")
s.value = r["url"]
except Exception as e:
app.notify("Check your internet connection")
app.notify(str(e))
app = URLShortner()
app.run()