docs(mastodon-crawler): account-ленты (4 автора по LLM/ИИ) + закрытие сессии [skip ci]

- proposal/design/tasks: lookup_acct → GET /api/v1/accounts/lookup → /accounts/<id>/statuses;
  примеры: @simon@fedi.simonwillison.net, @SebRaschka@mastodon.social,
  @stroughtonsmith@mastodon.social, @Edent@mastodon.social (даны пользователем 2026-10-03)
- WALKTHROUGH: хронология 2026-09-20 (HF RSS) и 2026-10-03 (OPML + mastodon)
- STATUS/TODO: OPML закрыта (018e5c7), mastodon-crawler — открыта (план)
This commit is contained in:
kpa39l
2026-10-03 12:35:45 +00:00
parent 018e5c715b
commit ed9d5b9370
6 changed files with 97 additions and 10 deletions
+31 -3
View File
@@ -33,11 +33,28 @@ CREATE TABLE mastodon_state (
Для публичной ленты всего инстанса: `hashtag: null` (или отсутствует).
Для account-ленты (посты конкретного автора): `lookup_acct`.
```yaml
- slug: simon-willison # аккаунт — аналог автора/канала
name: Simon Willison (fedi)
url: https://fedi.simonwillison.net/@simon
crawler: mastodon
base_url: https://fedi.simonwillison.net # инстанс аккаунта
lookup_acct: simon@fedi.simonwillison.net # lookup → /api/v1/accounts/<id>/statuses
direction: llm
lang: en
priority: P1
enabled: false
own: false
```
## crawler/mastodon_crawler.py (по образцу rss_crawler)
```python
# VESTI — Mastodon-краулер (Mastodon API, httpx).
# Читает источники sources.yaml crawler: mastodon, ленты /timelines/(tag/|public).
# Читает источники sources.yaml crawler: mastodon, ленты:
# /timelines/tag/<tag> | /timelines/public | /accounts/lookup + /accounts/<id>/statuses
# Дедуп по (instance, status.id), состояние в mastodon_state, посты в posts.
#
# Запуск:
@@ -54,10 +71,20 @@ def _clean_html(html: str) -> str:
"""HTML статуса -> текст: selectolax/bleach (как rss_crawler), убрать теги."""
# <p>, <a>, <br> -> текст; #хэштеги и @упоминания остаются (классификатор решает)
async def fetch_statuses(httpx_client, base_url: str, hashtag: str | None, max_id=None):
"""GET /api/v1/timelines/(tag/<tag>|public)?limit=40[&max_id=...] -> list[dict]."""
async def fetch_statuses(httpx_client, base_url: str, hashtag: str | None, account_id: str | None, max_id=None):
"""GET /api/v1/timelines/(tag/<tag>|public) или /accounts/<id>/statuses
?limit=40[&max_id=...] -> list[dict]."""
if account_id:
path = f"/api/v1/accounts/{account_id}/statuses"
elif hashtag:
path = f"/api/v1/timelines/tag/{hashtag}"
else:
path = "/api/v1/timelines/public"
...
def lookup_account(httpx_client, base_url: str, acct: str) -> str | None:
"""GET /api/v1/accounts/lookup?acct=<acct> -> account['id'] (или None)."""
def process_status(status: dict, base_url: str) -> dict | None:
"""Статус -> запись posts: {url, title, text, published_at, author}."""
# url = status['url'] or f"{base_url}/@{acct}/{id}"
@@ -66,6 +93,7 @@ def process_status(status: dict, base_url: str) -> dict | None:
def crawl_source(slug, source, dry_run=False):
"""Один источник: пагинация, дедуп, вставка, обновление mastodon_state."""
# if source.get('lookup_acct'): account_id = lookup_account(...) (кеш не нужен, редко)
# state = SELECT * FROM mastodon_state WHERE instance=host
# while page < MAX_PAGES:
# statuses = fetch_statuses(...)
+15 -3
View File
@@ -22,13 +22,25 @@ Signatures, подписки на аккаунты) — оверинжинири
## What Changes
- Новый вид источников `crawler: mastodon` в sources.yaml (slug = инстанс или хэштег):
- Новый вид источников `crawler: mastodon` в sources.yaml (slug = инстанс, хэштег или аккаунт):
- `mastodon.social` (публичная лента) — как единый «источник-fediverse»
- `fosstodon.org/tag/selfhosting`, `mastodon.social/tag/linux` — тематические
хэштег-ленты (аналог каналов TG по темам)
- **account-ленты** — посты конкретных аккаунтов (аналог авторов/каналов):
`GET /api/v1/accounts/lookup?acct=<acct>@<instance>` → id →
`GET /api/v1/accounts/<id>/statuses`. Примеры авторов по LLM/ИИ (даны
пользователем 2026-10-03, «с кого собирать новости»):
@simon@fedi.simonwillison.net (Simon Willison — LLM-инструменты/бенчмарки/
агенты/безопасность ИИ/цены), @SebRaschka@mastodon.social (Sebastian Raschka —
ML-исследования, «Build a Large Language Model From Scratch»),
@stroughtonsmith@mastodon.social (Steve Troughton-Smith — генеративный ИИ,
реверс-инжиниринг, ~35k подписчиков), @Edent@mastodon.social (Terence Eden —
ИИ: технологии и общество). В sources.yaml: `lookup_acct: simon@fedi.simonwillison.net`.
- Новый модуль `crawler/mastodon_crawler.py` (по образцу rss_crawler):
- читает источники с `crawler: mastodon`; при `feed_url`/`base_url` + опц. теге
- `GET /api/v1/timelines/tag/<tag>` или `GET /api/v1/timelines/public`, пагинация
- читает источники с `crawler: mastodon`; при `hashtag` — tag-лента, при
`lookup_acct` — account-лента, иначе public-лента
- `GET /api/v1/timelines/tag/<tag>` / `GET /api/v1/timelines/public` /
`GET /api/v1/accounts/lookup` + `/accounts/<id>/statuses`, пагинация
`max_id` до достижения `since_id` (последний обработанный id из состояния)
- дедуп по `status.id` (как sha256 у RSS), нормализация текста (HTML→text),
предел постов за запуск
@@ -10,6 +10,7 @@
- [ ] Пагинация max_id + дедуп по (instance, status.id) / sha256 url
- [ ] mastodon_state: чтение last_id, обновление после прогона, ошибки→status dead
- [ ] CLI: --all / --source <slug> / --dry-run; запуски в runs (mastodon:<slug>)
- [ ] Account-ленты: lookup_acct в источнике → GET /api/v1/accounts/lookup → /accounts/<id>/statuses (примеры 4 авторов по LLM/ИИ из proposal)
## Проверка
- [ ] Сухой прогон на реальном инстансе (mastodon.social/tag/linux) — посты читаются