Skip to content

Commit

Permalink
rename some files and classes mentionning twitter
Browse files Browse the repository at this point in the history
  • Loading branch information
amatissart committed Jan 30, 2025
1 parent c22783a commit 67454dd
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion backend/twitterbot/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.contrib import admin
from django.utils.html import format_html

from .models.tweeted import TweetInfo
from .models.history import TweetInfo


@admin.register(TweetInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from tournesol.models import Entity


class TwitterBot:
class TournesolBotClient:
def __init__(self, account):

credentials = settings.TWITTERBOT_CREDENTIALS
Expand Down
2 changes: 1 addition & 1 deletion backend/twitterbot/management/commands/load_tweetinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from tournesol.entities.video import YOUTUBE_UID_NAMESPACE
from tournesol.models.entity import Entity
from twitterbot.models.tweeted import TweetInfo
from twitterbot.models.history import TweetInfo


class Command(BaseCommand):
Expand Down
File renamed without changes.
22 changes: 11 additions & 11 deletions backend/twitterbot/tournesolbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
from tournesol.models.poll import DEFAULT_POLL_NAME, Poll
from tournesol.utils.contributors import get_top_public_contributors_last_month
from twitterbot import settings
from twitterbot.models.tweeted import TweetInfo
from twitterbot.twitter_api import TwitterBot
from twitterbot.models.history import TweetInfo
from twitterbot.client import TournesolBotClient
from twitterbot.uploader_twitter_account import get_twitter_account_from_video_id


Expand Down Expand Up @@ -176,9 +176,9 @@ def tweet_video_recommendation(bot_name, dest: list[str], assumeyes=False):
Accepted values are "twitter" and "bluesky".
"""

twitterbot = TwitterBot(bot_name)
bot_client = TournesolBotClient(bot_name)

tweetable_videos = get_video_recommendations(language=twitterbot.language)
tweetable_videos = get_video_recommendations(language=bot_client.language)
if not tweetable_videos:
print("No video reach the criteria to be tweeted today!!!")
return
Expand All @@ -198,11 +198,11 @@ def tweet_video_recommendation(bot_name, dest: list[str], assumeyes=False):
# Tweet the video
if "twitter" in dest:
tweet_text = prepare_text(video, dest="twitter")
tweet_id = twitterbot.create_tweet(text=tweet_text)
tweet_id = bot_client.create_tweet(text=tweet_text)

if "bluesky" in dest:
text = prepare_text(video, dest="bluesky")
atproto_uri = twitterbot.create_bluesky_post(text=text, embed_video=video)
atproto_uri = bot_client.create_bluesky_post(text=text, embed_video=video)

# Add the video to the TweetInfo table
tweet_info: TweetInfo = TweetInfo.objects.create(
Expand Down Expand Up @@ -280,8 +280,8 @@ def tweet_top_contributor_graph(bot_name, dest: list[str], assumeyes=False):
"""

twitterbot = TwitterBot(bot_name)
language = twitterbot.language
bot_client = TournesolBotClient(bot_name)
language = bot_client.language

top_contributors_qs = get_top_public_contributors_last_month(
poll_name=DEFAULT_POLL_NAME, top=10
Expand All @@ -302,20 +302,20 @@ def tweet_top_contributor_graph(bot_name, dest: list[str], assumeyes=False):

message_url = None
if "twitter" in dest:
tweet_id = twitterbot.create_tweet(
tweet_id = bot_client.create_tweet(
text=settings.top_contrib_tweet_text_template[language],
media_files=[top_contributor_figure]
)
message_url = f"https://twitter.com/{bot_name}/status/{tweet_id}"

if "bluesky" in dest:
post_uri = twitterbot.create_bluesky_post(
post_uri = bot_client.create_bluesky_post(
text=settings.top_contrib_tweet_text_template[language],
image_files=[top_contributor_figure],
image_alts=[settings.top_contrib_tweet_image_alt[language]]
)
post_id = post_uri.rsplit("/", 1)[-1]
message_url = f'https://bsky.app/profile/{twitterbot.bluesky_handle}/post/{post_id}'
message_url = f'https://bsky.app/profile/{bot_client.bluesky_handle}/post/{post_id}'

if message_url is not None:
# Post the tweet on Discord
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion infra/ansible/scripts/forget-secrets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ unset DISCORD_INFRA_ALERT_PRIVATE_WEBHOOK
unset DISCORD_TWITTER_WEBHOOK
unset PLAUSIBLE_ANALYTICS_SECRET_KEY
unset ATPROTO_PASSWORD_BOT_FR
unset ATPROTO_PASSWORD_BOT_EN
unset ATPROTO_PASSWORD_BOT_EN
2 changes: 1 addition & 1 deletion infra/ansible/scripts/get-vm-secrets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ ATPROTO_PASSWORD_BOT_FR=$(get_settings_value .TWITTERBOT_CREDENTIALS.\"@Tourneso
export ATPROTO_PASSWORD_BOT_FR

ATPROTO_PASSWORD_BOT_EN=$(get_settings_value .TWITTERBOT_CREDENTIALS.\"@TournesolBot\".ATPROTO_PASSWORD)
export ATPROTO_PASSWORD_BOT_EN
export ATPROTO_PASSWORD_BOT_EN

0 comments on commit 67454dd

Please sign in to comment.