Giter Club home page Giter Club logo

flask-news-app's Introduction

RSS News App written using Flask Framework

Installation

Runtime libraries

curl -O https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \
&& yum -y install epel-release-latest-7.noarch.rpm
yum -y install python-pip git
pip install --upgrade pip
pip install virtualenv
cd /var
git clone https://github.com/miztiik/flask-news-app.git
cd /var/flask-news-app

Create a Virtual Environment for our App

virtualenv /var/flask-news-app
source /var/flask-news-app/bin/activate

Install the App dependencies

pip install -r requirements.txt

Start gunicorn

The built-in development server is single threaded, We will need a multithreaded server to support production workloads. We will be using gunicorn here,

pip install gunicorn

Start the gunicorn and bind it port 8000 and listen on all interfaces

gunicorn --bind 0.0.0.0:8000 application &

Running as docker container

# Build using the attached docker file
docker build -t mystique/flask-news-app .

# (or easily) Pull the latest image from docker hub
docker pull mystique/flask-news-app

# Run the app
docker run -dti -p 8000:8000 --name newsapp docker pull mystique/flask-news-app

# If you want to override the port to any other custom port, say 80
docker run -dti -p 80:80 --name newsapp mystique/flask-news-app --bind 0.0.0.0:80

Optional

Lets use supervisor to manage our gunicorn. It will run gunicorn server in the background and also start it automatically on reboot.

Create .conf for Supervisord

touch /var/flask-news-app/flask-news-app-supervisor.conf
cat > << "EOF"
[program:flask-news-app-supervisor.conf]
command = /var/flask-news-app/bin/python
/home/deploy/.virtualenvs/flask-news-app/bin/gunicorn --bind 0.0.0.0:8000 wsgi:application -w 4
directory = /var/flask-news-app
# user = deploy
# stdout_logfile = /var/flask-news-app/logs/gunicorn/gunicorn_stdout.log
# stderr_logfile = /var/flask-news-app/logs/gunicorn/gunicorn_stderr.log
# redirect_stderr = True
environment = PRODUCTION=1
EOF

Update supervisor and Re-Start

(flask-news-app) $ supervisorctl reread
(flask-news-app) $ supervisorctl update
(flask-news-app) $ supervisorctl start flask-news-app-supervisor

Setup NGNINX as WebServer

Client Request ----> Nginx (Reverse-Proxy)
                        |
                       /|\                           
                      | | `-> App. Server I.   127.0.0.1:8081
                      |  `--> App. Server II.  127.0.0.1:8082
                       `----> App. Server III. 127.0.0.1:8083

About the Code

Python Flask application to fetch latest news from a variety of sources

News Fetcher

The __init__.py has the RSS feed parser code and the various RSS links to new media sites hardcoded along with the news relevancy timeline

Unit Tests

test_app.py has three test cases

  • Make a GET request for news page and check if http return code is 200
  • Make a POST request and check if http return code is 200
  • Make a POST request for invalid url and check return code is 302

If you are interested, Please feel free to add to them :)

To Do List

flask-news-app's People

Contributors

dependabot[bot] avatar miztiik avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.