Example: São Paulo City Hall news
A complete project that uses obskitpy: a robot extracts the news from
prefeitura.sp.gov.br/noticias, stores it in Elasticsearch
(noticias-sp index) and the dashboard shows the extracted data and the robot's health.
The code is in exemplo-noticias-sp/.
How the data is obtained
The "All news" list on the page is built in the browser by JavaScript, so the HTML comes without any news.
The robot calls the same public portal API (Liferay) that the JavaScript calls, one day at a time.
Each item becomes a document with title, URL, dates, summary, text, word count, links, images and type
(noticia or agenda: "Dia do prefeito" is the daily agenda). The id is the City Hall's own, so running it again
updates instead of duplicating.
Use it sparingly
That is about 7 requests per run. If the portal changes its structure, the parse error shows up on the dashboard.
Running it
git clone https://github.com/pedrowill-dev/obskitpy && cd obskitpy/exemplo-noticias-sp
python3 -m venv .venv && .venv/bin/pip install -r requirements.txt
.venv/bin/obskitpy up # stack + dashboard (~1 min the first time)
.venv/bin/python -m noticias_sp # extracts the last 7 days
Dashboard: http://localhost:5601/app/dashboards#/view/noticias-sp-observability?_g=(time:(from:now-7d,to:now))
| Variable | Default | |
|---|---|---|
DIAS |
7 |
how many days back (counting today) |
RPA_INTERVAL_SECONDS |
0 |
0 = run once; >0 repeats every N seconds |
ELASTICSEARCH_URL |
http://localhost:9200 |
What obskitpy brought
This is all it took in the code:
shutdown = obskitpy.setup("noticias-sp") # logs + traces + metrics
tracer = obskitpy.tracer("noticias_sp") # spans: execucao > dia.processar > dia.baixar | noticia.processar
processed = obskitpy.meter("noticias_sp").create_counter("noticias.processadas") # custom metric, by status
log.exception("falha ao processar notícia") # comes out with error.type / error.origin / error.chain
The top panels (logs, errors, runs, duration, errors by type/origin) come from obskitpy init.
The bottom ones (extracted news, posts per day, longest articles, news table) belong to the project, in
extend_dashboard.py;
see Dashboards.
Known limitations
- The API does not return the news categories, so there is no per-category panel.
- "Runs with errors" only counts failures that bring down the whole run; per-day/per-article failures are handled and show up under Errors.
- The publication time is stored in UTC; the robot queries the days in the São Paulo time zone (-03:00).