Czech sentiment analyzer project aka “czester”

Hey! Just finished my latest project, the Czech language sentiment analyzer. The official name of this tool is “CZESTER”. Spend a lot of my time with this project the last couple of months, but I feel it was definitely worth it.

I learned a lot of new facts about multi-threaded web scraping, supervised machine learning, natural language processing, Flask and Chart.js integration which I used for site statistics page and also about deploying Flask machine learning web applications to Pythonanywhere and Heroku. This was probably the coolest project I worked on in a while.

It’s currently deployed to and I’d love to hear what you think about it. The details describing this project are located here:

Flask, MVC, Github integration example project finished

I just finished a fun and challenging project in Python. It’s a project based on Flask web microframework allowing the user to work with branches and files of their Github repository. This functionality is accessible via a locally running web application but the same functionality is also covered with rest api endpoints. These api endpoints are also used as endpoints for tests.

purpose of this Flask project is to demonstrate:

  1. how to deliver the same features in both api endpoints and static html forms in one Flask project
  2. how Flask can be used with the MVC design pattern with the controller imported as Flask blueprints
  3. how Flask can deal with Github integration using the Github API v3 (used as the model “persistence” layer in the MVC design pattern)
  4. api endpoint pytest testing using the app factory import pattern
  5. ability of such a web application to gracefully fail on Github integration exceptions

Have a look here:

The basic idea behind this example project is this:


few screenshots from the app:

API connection “retry logic with a cooldown period” simulator ( Python exercise )

This is a very simple API call “circuit-breaker” style simulator I’ve written in Python. But since it’s a stateless code snippet, you should call it most likely a “retry logic with a cooldown period” simulator. But there are valid use case scenarios when stateless is the desired state type. For example when a validation of a dataset against a service can either pass or fail and throw an exception and cause the execution flow to halt. This is typical for data-flow styled apps. In such case the circuit-open state is not acceptable. Anyway the goal is to make sure, that whenever we have a connection (or timeout) error during the API call ,we retry after 10 seconds, after 20 seconds, after 30 seconds and then quit trying. The ConnectionError exception is simulated using a non-routable address

However in the microservices world, if you want to implement the full-scale state-full circuit-breaker, please have a look at this article.

import datetime
import time
import logging
import requests

iterator = 1
attempt = 1

# while cycle to simulate connection error using non-routable IP address
while iterator < 40:
        # if iterator inside the range to simulate success
        if 1 < iterator < 8:
            r = requests.get('')
        # else iterator outside the range to simulate the error event
            r = requests.get('')
        if r.status_code !=
            logging.error('Wrong request status code received, %s', r.status_code)
        r = r.json()
        attempt = 1
    except (requests.exceptions.ConnectionError, requests.exceptions.Timeout,
            requests.exceptions.ConnectTimeout, requests.exceptions.ReadTimeout) as conn_err:
        print(f'bingo, ConnectionError, now lets wait {attempt * 10} seconds before retrying', (
        time.sleep(attempt * 10)
        attempt += 1
        if attempt > 3:
            logging.error('Circuit-breaker forced exit')
            raise conn_err
    iterator += 1

Also try avoiding Python time.sleep() method in AWS Lambdas as this would not be cost efficient, AWS Step Functions would be much more appropriate.

*Updated March 14th 2019: Considering the cost analysis in this article, it might be actually ok to have time.sleep() in the Lambda, depends on your use case though.

Spinning up a Docker container with Flask and Python

Imagine you need to replicate an existing web API returning a JSON ( listing all feeds in some system ) on your local machine for further development purposes and possible extensions. Today I’ll demonstrate how to achieve this using Docker container , Python and Flask. Note that this tutorial requires some previous experience with Python and Docker. Have a look at Flask, it’s a powerful and easy to use Python web framework.

The source web API we’ll be replicating is returning a valid JSON structure listing all the feeds:

  "feed_name": "feed1",
  "feed_type": "feed type 1",
  "filemasks": [
  "feed_name": "feed2",
  "feed_type": "feed type 2",
  "filemasks": [

Let’s save this dummy JSON file as feeds.json on our local file system.

Next we’ll setup the environment and start with Docker:

mkdir docker-api

mkdir docker-api/app

mkdir docker-api/feeds

cd docker-api

#1) create Dockerfile as:

FROM python:3.6-stretch

COPY . .

RUN pip install -r requirements.txt


ENTRYPOINT ["python3"]

CMD [""]

#2) create requirements.txt as :


#3) download the feeds.json file from the website
to your local filesystem into docker-api/feeds/


Let’s move forward with the Python application, which is reading from the Docker image

the feeds.json file and exposing this JSON to the Flask web API. We won’t be stepping into

any other HTTP methods besides GET, ( the default Flask route method ), we’ll focus just on returning the complete JSON file listing all the feeds.


I prepared the Python app in the location docker-api/app/ and it is looking like this:

import os
from flask import Flask
from flask import Response

app = Flask(__name__)

def returner():
    path = os.path.abspath(os.curdir) + '/feeds/feeds.json'

    with open(path,"r") as f:
        data =
        resp = Response(response=data, status=200, mimetype="application/json")
        return resp

if __name__ == '__main__':, host='')

The next step is spinning up the docker container ( once we build the image of course )

cd docker-api/

docker build -t feeds . 
docker run -d -p 5000:5000 feeds 
docker container list 
*optionally docker container kill(or stop) container_id in
case you need to "restart" the container
Btw. docker kill vs docker stop is an interesting topic and is discussed for example here
Let’s confirm that your Python project structure is looking like this:

and voila, after running docker run -d -p 5000:5000 feeds , if you lookup the webpage


in your web browser, you should be getting the response with the desired JSON listing all the feeds.

You might want to check-out also curl.