Skip to content

This is a simple URL shortener in Flask. Shortens URL upto length 512 characters to 6 characters. Made using Flask-SQLAlchemy. This URL shortener will be able to redirect links and keep stats on the number of times each link was visited. Also has HTTP Basic Authentication to view stats. All this data will be stored in a sqlite3 database.

Notifications You must be signed in to change notification settings

ksh168/smolink-url_shortener

Repository files navigation

URL_Shortener - smolink

smolink-url_shortener

Access the service here[no longer available due to abuse by spammers]

Open Source Love svg1 PRs Welcome

This project was born out of my curiosity for how URL Shorteners work.

This is a simple URL shortener in Flask.

Shortens URL upto length 512 characters to 6 characters.

Made using Flask-SQLAlchemy. This URL shortener will be able to redirect links and keep stats on the number of times each link was visited.

Also has HTTP Basic Authentication to view stats.

All this data will be stored in a sqlite3 database

Goals of this project

✅ Users can create personalized URLs

✅ Check user input to make sure it's URL

✅ Support for ftp[s]

✅ Ability to view stats for individual links by adding "/stats" to URL

✅ Public HTTPS website deployed

  • User can create a account and then generate and manage all the links and their stats from there

  • Security against cyber attacks

(more will be added along the way)

  • "link" Table in the Database

User Interface

  • UI walk-through

  • Index page

  • Short URL generated

  • Custom Short URL generated

  • Incase custom selected URL already exists

  • Individual link Statistics

  • Global Statistics (Needs admin HTTP Authentication)

Quick Setup:

  • Fork and Clone the repository using-
git clone https://github.com/ksh168/smolink-url_shortener.git

Always recommended to create a virtual environment

Method1: (Recommended)
  • sudo apt install python3-venv

  • Create a virtual environment called myvenv

    python3 -m venv ./myvenv

  • Activate myvenv

    source myvenv/bin/activate

  • Install dependencies

    pip install -r requirements.txt

Method2:
  • Create virtual environment and install flask

    pipenv install flask

  • To start shell and enter the venv

    pipenv shell

  • Dependencies:(this step might not be needed)

    pipenv install python-dotenv

    pipenv install sql-alchemy

Now headover to Project Directory-

cd smolink-url_shortener
  • Create a Branch-
git checkout -b <branch_name>

Now to create the database

  1. Start python in terminal

    python

  2. 	from url_shortener import create_app
  3. 	from url_shortener.extensions import db
  4. 	from url_shortener.models import Link
  5. To create tables and database

    	db.create_all(app = create_app())
  6. To exit python console

    	exit()
  • To view database, write in terminal

    sqlite3 url_shortener/db.sqlite3

  • To see the table names in database

     	.tables
  • To query the database

     SELECT * FROM link;
  • To delete table contents but not table

     DELETE FROM link;
  • To exit sqlite3

     	.exit

To run the app

export FLASK_APP=run.py
flask run

Inside the url_shortener folder there's a file called config.json. This file contains default values for DATABASE_URL, USERNAME and PASSWORD. Change it according your requirements.

Contributing

Checkout the contributing guide

Community

  • You can chat with the community here.

Acknowledgements

This project was made using GitHub Codespaces Beta. Thanks to them for providing me early access to their such beautiful and useful feature.

Contributors

About

This is a simple URL shortener in Flask. Shortens URL upto length 512 characters to 6 characters. Made using Flask-SQLAlchemy. This URL shortener will be able to redirect links and keep stats on the number of times each link was visited. Also has HTTP Basic Authentication to view stats. All this data will be stored in a sqlite3 database.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published