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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user