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(...)