fix: Resolve duplicate interaction detection and add usernames

- Add processed_ids set to prevent duplicate inserts when a tweet is
  both a mention and a comment (same external_id)
- Enhance get_mentions() to fetch usernames via user expansions
- Update fetch_interactions to prefer username over numeric author_id

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-29 10:04:58 +00:00
parent f4f0a2d230
commit 5f04aa0cce
2 changed files with 29 additions and 4 deletions

View File

@@ -189,22 +189,31 @@ class XPublisher(BasePublisher):
me = self.client.get_me()
user_id = me.data.id
# Obtener menciones
# Obtener menciones con información de usuarios
mentions = self.client.get_users_mentions(
id=user_id,
since_id=since_id,
max_results=50,
tweet_fields=['created_at', 'author_id', 'conversation_id']
tweet_fields=['created_at', 'author_id', 'conversation_id'],
user_fields=['username'],
expansions=['author_id']
)
if not mentions.data:
return []
# Crear mapa de usuarios para obtener usernames
users_map = {}
if mentions.includes and 'users' in mentions.includes:
for user in mentions.includes['users']:
users_map[str(user.id)] = user.username
return [
{
"id": str(tweet.id),
"text": tweet.text,
"author_id": str(tweet.author_id),
"username": users_map.get(str(tweet.author_id), str(tweet.author_id)),
"created_at": tweet.created_at.isoformat() if tweet.created_at else None
}
for tweet in mentions.data