A Django site that shows a random fact every day.
The facts come from public web pages. A management command scrapes them into the database. An extractor reads one site, a formatter cleans the text, and a storage class writes the result. See Scraping for more info.
Run it on the host machine. No Docker.
uv sync
uv run python manage.py tailwind install
uv run python manage.py migrateThen start two processes:
uv run python manage.py tailwind start
uv run python manage.py runserverTo run the app, use Docker Compose to execute the two services, both from the same image:
webapplies the migrations, registers the daily schedule, then serves the site with gunicorn on port 8000.qclusterruns the Django Q worker, which picks the fact of the day at midnight.
To build and run:
cp .env.example .env # then set the real values
docker compose up -d --buildmanage.py scrape_facts takes an extractor and a storage class, both by class
name:
uv run python manage.py scrape_facts ScienceFocus121FactsExtractor DBStorageIn the container:
docker compose exec web python manage.py scrape_facts ScienceFocus121FactsExtractor DBStorageExtractors, from facts/scraping/extractors/:
| Class | Needs Chromium |
|---|---|
ScienceFocus121FactsExtractor |
no |
TodayInterestingFactsAdultsExtractor |
no |
HooRayHeroesAnimalsFunFactsExtractor |
yes |
HooRayHeroesMythBustingFunFactsExtractor |
yes |
DBStorage is the only storage class.
Options:
| Option | Effect |
|---|---|
--formatter <Class> |
Use DefaultFactFormatter or HoorayHeroesFactFormatter instead of the extractor default. |
--override |
Replace facts whose identifier already exists. |
--delete |
Delete the scraped facts instead of saving them. --override is ignored. |
The two HooRayHeroes extractors drive a headless browser with playwright. The image installs Chromium during the build. On the host, install it once:
uv run playwright install chromium