Skip to content

tmvfb/flask-webpage-analyzer

Repository files navigation

flask-webpage-analyzer

Website flask-webpage-analyzer-production.up.railway.app Actions Status Github Actions Status Maintainability

Tools used

Tool Description
Flask Web development, one drop at a time
Gunicorn Python WSGI HTTP Server for UNIX
psycopg2 Python-PostgreSQL Database Adapter for Python
Beautiful Soup Python library for pulling data out of HTML and XML files
requests HTTP for Humans
Flask-Babel Implements i18n and l10n support for Flask

Description

Simple web application and SEO tool that scrapes h1, title and description tags for the desired website. Backend is written in Python using Flask for routing, psycopg2 for PostgreSQL database management, Beautiful Soup and requests for HTML parsing. Flask-Babel is used for adding Russian translation. Database and final project are deployed using render. Frontend relies on Bootstrap 5.0 and jinja2 templating engine. Database is reset on every server restart.

image

Prerequisites

  • Python >=3.7.10
  • pip >=19.0
  • poetry >=1.2.0
  • PostgreSQL database for local deploy

Code usage

To reuse this code, a PostgreSQL database server is needed.

  1. git clone https://github.com/tmvfb/flask-webpage-analyzer.git
  2. cd flask-webpage-analyzer
  3. make install to build dependencies
  4. sh setup.sh to configure environment variables. You will be prompted to enter your database URL

Successful configuration can be started using either make dev (Flask dev server) or make start (gunicorn production server).

Acknowledgements

Made as a project for hexlet.io python course.

Miscellaneous

Update localization files:

  1. pybabel extract -F babel.cfg -o messages.pot .
  2. pybabel update -i messages.pot -d translations
  3. Complete the corresponding messsages.po file
  4. pybabel compile -d translations
  5. flask --app page_analyzer:app run --extra-files translations/{LANGUAGE}/LC_MESSAGES/messages.mo to update localization files. Server restart works as well

New translations can be added using following commands:

  1. pybabel extract -F babel.cfg -o messages.pot .
  2. pybabel init -i messages.pot -d translations -l {LANGUAGE} (insert 2-digit country code instead of {LANGUAGE})
  3. Complete the corresponding messsages.po file
  4. pybabel compile -d translations
  5. flask --app page_analyzer:app run --extra-files translations/{LANGUAGE}/LC_MESSAGES/messages.mo to update localization files. Server restart works as well