Skip to content

guoguo12/gsheets-url-shortener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

URL Shortener

This code accompanies "A Concise URL Shortener in Python".

Instructions

  1. Follow the instructions in the blog post to set up the database (spreadsheet).
  2. Acquire access to a machine with a fixed, public IP address. I use a cheap VPS from DigitalOcean (non-referral link).
  3. Clone this repo onto your server: git clone https://github.com/guoguo12/gsheets-url-shortener.git.
  4. Change SHEET_ID in shortener.py to your spreadsheet's ID, and also configure PORT.
  5. Install dependencies with pip install -r requirements.txt. (Make sure you're using the pip for your Python 3 installation.)
  6. Run the server: python3 shortener.py.

You may also want to register a domain name and point it at your server.

Potential improvements

Ideas for improving the code:

  • Find a way to modify the spreadsheet such that the server crashes while parsing the CSV. Then use Python's csv module to parse the database instead.
  • When a user requests a short URL that isn't in the database, our server responds with an ugly "Internal Server Error" page. Handle this gracefully.
  • Cache database queries using functools.lru_cache, then add a special endpoint for clearing the cache.
  • Keep track of how many times each short URL has been accessed. (Bonus points for writing click-count data back to the spreadsheet.)

About

A simple URL shortener that uses Google Sheets as a backend.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages