Imports and APIs for social

Aggiunta la chiave per X in .env.example
Aggiunto docker a pyproject.toml
This commit is contained in:
Nunzi99
2025-10-10 20:32:45 +02:00
parent e2dfa98403
commit ed6e5f6e3d
3 changed files with 14 additions and 12 deletions

View File

@@ -38,3 +38,13 @@ CRYPTOPANIC_API_KEY=
# https://www.reddit.com/prefs/apps
REDDIT_API_CLIENT_ID=
REDDIT_API_CLIENT_SECRET=
# Per ottenere questa API è necessario seguire i seguenti passaggi:
# - Installare l'estensione su chrome X Auth Helper
# - Dargli il permesso di girare in incognito
# - Andare in incognito ed entrare sul proprio account X
# - Aprire l'estensione e fare "get key"
# - Chiudere chrome
# Dovrebbe funzionare per 5 anni o finchè non si si fa il log out, in ogni caso si può ricreare
X_API_KEY=

View File

@@ -35,6 +35,7 @@ dependencies = [
# API di social media
"praw", # Reddit
"docker", # Necessario per usare Rettiwt per X
]
[tool.pytest.ini_options]

View File

@@ -1,11 +1,11 @@
'''
THIS CURRENTLY DOES NOT WORK AS INTENDED DUE TO THE FACT THAT THE TWEETS AREN'T IN CHRONOLOGICAL ORDER
Usiamo l'API rettiwt per ottenere dati da X aggirando i limiti dell'API free
Questo potrebbe portare al ban dell'account anche se improbabile, non usare l'account personale
Per farlo funzionare è necessario installare npm in un container docker ed installarlo con npm install -g rettiwt-api dopo essersi connessi al docker
https://www.npmjs.com/package/rettiwt-api
'''
import os
import docker
import json
from .base import SocialWrapper, SocialPost, SocialComment
@@ -24,16 +24,7 @@ class XWrapper(SocialWrapper):
'BTC_Archive',
'elonmusk'
]
self.api_key = "ADD_API_KEY"
'''
Per ottenere questa API è necessario seguire i seguenti passaggi:
- Installare l'estensione su chrome X Auth Helper
- Dargli il permesso di girare in incognito
- Andare in incognito ed entrare sul proprio account X
- Aprire l'estensione e fare "get key"
- Chiudere chrome
DOvrebbe funzionare per 5 anni o finchè non si si fa il log out, in ogni caso si può ricreare
'''
self.api_key = os.getenv("X_API_KEY")
# Connection to the docker deamon
self.client = docker.from_env()
# Connect with the relative container
@@ -41,7 +32,7 @@ class XWrapper(SocialWrapper):
self.social_posts: list[SocialPost] = []
def get_top_crypto_posts(self, limit = 5) -> list[SocialPost]: #-> list[SocialPost]:
'''
Get the top crypto tweets from X, the limit is reffered to the number of tweets for each user
Otteniamo i post più recenti da X, il limite si applica al numero di post per ogni utente nella lista interna
'''
social_posts: list[SocialPost] = []
for user in self.users: