losses.py is a Python script that allows to watch an actual data of the russian army losses in the Russo-Ukrainian War.
You can watch the data in the console or generate an image with this. For this you'll need file with a background and file with a font in .ttf format.
For the image making part, you'll have a file config.json
created when you use script for creating image for the first time. Detailed description of the file and usage can be found down bellow.
The data comes from the Ministry of Finance website. Script parses, strips and prepares it to be printed as table or written on image.
This script was made as a final project of CS50’s Introduction to Programming with Python.
Here you can see how the script prints data to the console:
If you run the script with image generation mode you'll get something like this:
Console stats output:
- Install Python 3.
- Run
pip install -r requirements.txt
to install dependencies. - Run
python losses.py
Generating image:
- Install Python 3.
- Run
pip install -r requirements.txt
to install dependencies. - Run
python losses.py -i
. This will generate config file. - Edit
config.json
, specifying resource files and font sizes. - Run
python losses.py -i
again. This will produceresult.jpg
file.
Config file example:
{
"background_path": "./resources/image.jpg",
"font_path": "./resources/font.ttf",
"font_size": 24,
"text_color": "white",
"header_font_size": 34,
"header_text": "Протягом 24.02-%s\n орієнтовані втрати противника склали:",
"header_color": "yellow",
"tint_amount": 0.35
}
NOTE: header_text
must contain %s
for the current date.
Also, you can run tests for the script. For this:
- Install pytest:
pip install pytest
- Run
pytest test_project.py