nikolausschueler / lotto

Little lotto number generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The Lotto random number web app

What is this?

A while ago, we played Lotto (the German "Sechs aus Neunundvierzig"[1]) in the family (ignoring my hints about the improbability of actually winning in a lottery). So I, as the mathematician, was asked to come up with random numbers. After a while, I got too lazy to make up numbers, so I wrote this little web application.

It is written in Python, using the Flask framework.

You can see the app running on http://server.drnik.org:10770. [2]

As I have no reverse proxy for a nice URL set up so far (see the to do section), the app is running on a port that tries to resemble the german word LOTTO in some kind of leetspeak.

To get a new set of numbers, reload the page. A button for this is on the wish list, see the to do section.

Usage

The easiest way to run this app is using Docker Compose. If you don’t have it already, install docker-compose. Then go to the directory where your clone of this repo is and just run:

$ docker-compose up

If you want, you can run this app manually. Just create a virtualenv with Python 3 and install Flask:

$ mkvirtualenv -p python3 venv
$ pip install flask
$ lotto/lotto.py

Alternatively, you can install Flask on your machine and run the app.

Refinements/Changelog

Initially, the image was based on plain Ubuntu. Now it uses an official Python image, which again is based on Alpine Linux. This change makes the resulting image smaller by a significant amount. Instead of slightly over 400 MB it now is just 50 MB big.

The other advantage of using the Python image is of course that it saves you some installation steps, especially the installation of Python itself.

I first tried to use the Python image python:3.10-rc-buster as base image for the container. This actually increased the image size up to nearly 900 MB. So I switched to an Alpine-based image.

All the Python images can be found here: https://hub.docker.com/_/python.

TODO

This app is a little exercise in Docker and Docker Compose for me. It works, but there sure is room for improvement. Some ideas are:

Tests

Add Selenium tests for the GUI. Add application tests for Flask. And, if you one day have a REST interface, test that too.

Run on HTTPS

Bummer, right now the thing runs on HTTP. In 2021. Really? Bad boy. Make it run on HTTPS. A certificate from Let’s Encrypt would do.

Add a button

In the moment you have to reload the web page to get a new set of numbers. Provide a button that says something like "Give me more numbers".

Docker finetuning

Specify an explicit non-root user. Use a WORKDIR. Check the image with hadolint. Best set up linting (for Docker and Python) automatically. Find out, which automatisms/triggers GitHub offers for this (if any).

Nice URL

Let it run under a URL like http://example.com/lotto. For this, you need to set up a reverse proxy. As we already use Docker Compose, the proxy is best set up the same way.

Add a REST API

Add a REST API. Charge $5 for each call of the API. Get indecently rich.[3]


1. Roughly translatable as "Six from fortynine".
2. Unless I play around with the installation and the app is offline.
3. Only joking. But the part about the REST API is true. Would be really nice to have that.

About

Little lotto number generator

License:GNU General Public License v3.0


Languages

Language:Dockerfile 25.8%Language:Python 25.2%Language:HTML 24.7%Language:CSS 24.2%