feat: Add follower tracking to interactions

- Add get_followers() method to X publisher
- Track new followers as "follow" interaction type
- Update daily reports to show followers separately
- Store follower name, username, bio, and profile image

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-29 23:07:28 +00:00
parent f5c6554fc3
commit b6823651e0
3 changed files with 113 additions and 9 deletions

View File

@@ -138,9 +138,44 @@ def fetch_platform_interactions(platform: str):
processed_ids.add(external_id)
new_comments += 1
# Obtener nuevos followers (solo para X por ahora)
new_follows = 0
if platform == "x" and hasattr(publisher, 'get_followers'):
followers = run_async(publisher.get_followers(max_results=100))
for follower in followers:
# Usar "follow_" prefix para distinguir de tweet IDs
follower_id = follower.get("id")
external_id = f"follow_{follower_id}"
if external_id in processed_ids:
continue
existing = db.query(Interaction).filter(
Interaction.external_id == external_id
).first()
if not existing:
interaction = Interaction(
platform=platform,
interaction_type="follow",
external_id=external_id,
author_username=follower.get("username", "unknown"),
author_name=follower.get("name"),
author_avatar_url=follower.get("profile_image_url"),
content=follower.get("description"), # Bio del usuario
interaction_at=datetime.utcnow() # No sabemos cuándo siguió exactamente
)
db.add(interaction)
processed_ids.add(external_id)
new_follows += 1
db.commit()
return f"{platform}: {new_mentions} menciones, {new_comments} comentarios nuevos"
result = f"{platform}: {new_mentions} menciones, {new_comments} comentarios"
if new_follows > 0:
result += f", {new_follows} follows nuevos"
return result
except Exception as e:
db.rollback()