/URL-shortening-service

URL shortening web service built with Python, Flask and Google Cloud Platform

Primary LanguagePython

URL shortening service

*UPDATE

Latest files with updates including GCP and other new features are in the GCP folder.

For more information, check the GCP version section below.

Table of contents

About this Project

URL shortening web service which provides short aliases and custom aliases redirecting to original URLs.

initial version

Initial code only uses

and is a very simple web application which shortens a URL by creating a short URL alias with a 6 characters long generated key.
Instead of using a Web database, it stores all the information (original URLs and aliases) to a JSON file and uses a text file to check existing keys to avoid duplication.

GCP version

In addition to the short link feature, 1. default expiration time, 2. custom link feature, 3. custom expiration feature and 4. simple link analysis were added.
Users can create a custom URL alias with characters of their choice and can also set a custom expiration date to both short links and custom links.

Instead of using JSON, it uses a NoSQL document database GCP Firestore to manage all the data by deploying the application to GCP App Engine.

(to see an example : https://short-321807.an.r.appspot.com/)

Built with

This project is built using the following frameworks/services

Getting Started

Prerequisites

$ pip install python-dateutil
$ pip install Flask

   follow this document for setup

$ pip install --upgrade google-cloud-firestore

   follow this document for setup

   follow this document for setup

Installation

initial version

  1. clone this repository
$ git clone https://github.com/mikako-shirai/URL-shortening-service.git
  1. create and activate a virtual environment
$ python3 -m venv venv
$ . venv/bin/activate

  (to deactivate)

(venv)$ deactivate
  1. install Flask in the virtual environment
(venv)$ python3 -m pip install flask
  1. run main.py
(venv)$ pytho3 main.py
  1. go to http://127.0.0.1:5000/ to view the application

GCP version

  1. clone this repository
$ git clone https://github.com/mikako-shirai/URL-shortening-service.git
  1. move to GCP directory
$ cd GCP
  1. set up Firestore
$ export GOOGLE_APPLICATION_CREDENTIALS="KEY_PATH"

  *replace KEY_PATH with the path of the JSON file that contains your service account key

  1. upload cron jobs to App Engine
$ gcloud app deploy cron.yaml
  1. deploy the application to App Engine
$ gcloud app deploy
  1. go to https://YOUR_PROJECT_ID.an.r.appspot.com/ to view the application

  (to run unit tests)

$ python3 -m unittest tests/suite.py

Usage

initial version example

example

GCP version example

example