How mrkocmocc/osu.eventaggregator works
Purpose and Entry Points
OSU.EventAggregator collects Orenburg State University event data from news and open-day pages, persists normalized events, and exposes them through a Flask REST API plus a lightweight browser UI. Process startup is run.py; application construction and extension registration are centered in app/__init__.py.
Application and HTTP Boundary
The Flask application serves API operations under /api and the HTML interface. API routes provide event listing/detail/upcoming queries, statistics, parser triggering, and JSON import/export. app/api/routes.py is the orchestration boundary between requests, parsers, ORM queries, and serialization; app/templates/index.html consumes the service as a management/viewing interface.
Canonical Event Persistence Model
Event is the system’s canonical normalized record: source-specific identifiers, event metadata, source provenance, parsing timestamps, active state, and audit timestamps. Uniqueness of external_id supports repeatable parsing and update-or-create behavior rather than uncontrolled duplicates. The model and database integration reside in app/models.py, with database settings supplied via app/config.py.
Source Ingestion: News
The news ingestion path fetches OSU news pages, extracts candidate events from HTML and full article content, infers dates/types, and returns event-shaped records for persistence. It supports month/year scope, which the parse API can pass through. Its external dependency is the OSU news website, accessed over HTTP and parsed with Requests/BeautifulSoup. Primary implementation: app/parsers/news_parser.py.
Source Ingestion: Open Days
The open-day parser targets the university applicant/open-day source and interprets tabular HTML, including merged cells, to produce dates, times, locations, and event type. This is a separate source-adapter boundary from news parsing but converges on the same Event schema and persistence path. Primary implementation: app/parsers/dod_parser.py.
Data and Control Flow
A client invokes POST /api/parse in app/api/routes.py, optionally selecting news, dod, or both. Routes instantiate/dispatch source parsers; parsers retrieve and transform external HTML into normalized dictionaries; persistence uses the Event model and external IDs to create or update database rows. Read APIs query the same store with pagination, source/type/activity/date filters; export serializes filtered records, while import validates supplied event-shaped JSON and merges it into the canonical store.
Runtime and Infrastructure
The service is Python/Flask with SQLAlchemy and Flask-Migrate, backed by PostgreSQL 15. Docker Compose defines the application (web, port 5000) and PostgreSQL (db, port 5432) runtime topology with persistent database storage. Environment-based database credentials/URL and Flask secret configuration are represented by .env and app/config.py; container packaging is in Dockerfile and docker-compose.yaml.
Main entry points: routes.py API routes · docker-compose.yaml Compose topology · models.py Event · __init__.py App factory
Components 16
Clients
- Browser UI · Management and event viewing interface.
- API client
Flask service
- Process startup
run.py - App factory · Constructs the application and registers extensions.
app/__init__.py - API routes · Serves /api reads, parsing, import, and export.
app/api/routes.py - HTML interface
app/templates/index.html - Event · Canonical normalized event record keyed by external_id.
app/models.py - Configuration · Database URL and Flask settings.
app/config.py
Source ingestion
- News parser · Extracts and normalizes event candidates from news articles.
app/parsers/news_parser.py - Open-day parser · Parses tabular applicant/open-day data, including merged cells.
app/parsers/dod_parser.py - OSU news site
- Applicant/open-day site
Runtime
- Compose topology · Runs web on 5000 and PostgreSQL on 5432.
docker-compose.yaml - Web image
Dockerfile - PostgreSQL 15 · Persistent canonical event store.
- Environment values · Supplies credentials and secret configuration.
.env
Connections 20
- Process startup → App factory: starts
- App factory → API routes: registers
- App factory → Configuration: loads
- Browser UI → HTML interface: loads HTML
- Browser UI → API routes: calls /api
- API client → API routes: calls /api
- API routes → News parser: dispatches parse
- API routes → Open-day parser: dispatches parse
- News parser → OSU news site: fetches HTML
- Open-day parser → Applicant/open-day site: fetches HTML
- News parser → Event: normalized records
- Open-day parser → Event: normalized records
- API routes → Event: queries and upserts
- Event → PostgreSQL 15: persists
- Configuration → Environment values: reads values
- Configuration → PostgreSQL 15: database URL
- Compose topology → Web image: builds web
- Compose topology → PostgreSQL 15: runs db
- Compose topology → Process startup: runs web
- Compose topology → Environment values: loads