pyBegin / projects / url-shortener
🔗

URL Shortener

I built code quality tools into project (linting, formatting, type annotation checks)

52 lines🖥 Desktop only

URL Shortener

Goal is to have a resuable class that engineers can use or copy/paste into their apps for shortening URLs. Engineer will be able to use any shortening library of their choice. In my example I will be using pyshorteners. I will also build an example with bringing a different library into the codebase.

Using url shortener within this project

setup

  1. Navigate to projects\url_shortener
  2. Create virtual environment python -m venv venv
  3. Activate virtual environment (I am on windows, different on MacOs) venv\Scripts\activate
  4. pip install -r requirements.txt

execution

  1. python app/main.py

example of execution via terminal

(venv) python-beginner-projects\projects\url_shortener>`python app/main.py`
Enter the URL you want to shorten: https://www.bing.com/search?q=bing&cvid=e42b0995bcd045849a216437b88847be&gs_lcrp=EgZjaHJvbWUyBggAEEUYOTIGCAEQRRg8MgYIAhBFGDwyBggDEEUYPDIGCAQQRRg8MgYIBRBFGDzSAQczOTlqMGo0qAIIsAIB&FORM=ANAB01&PC=U531
Shortened URL: https://tinyurl.com/275h2qwv

Extras

I built code quality tools into project (linting, formatting, type annotation checks)

  1. ruff check . - linter
  2. ruff check --fix - fix linting
  3. ruff format - formatting
  4. mypy . - type annotation checking

Author: justinjohnson-dev Last Update: 05/25/2024

Pyodide-runnable

No — it uses pyshorteners/requests to call a live URL-shortening API and depends on pywin32.