Skip to content

Commit

Permalink
Stop posting new questions to X
Browse files Browse the repository at this point in the history
Instead ask people to follow us on Bluesky and Mastodon

Fixes #381
  • Loading branch information
knatten committed Feb 21, 2025
1 parent 4d14edb commit 8544430
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions quiz/management/commands/auto_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,23 @@ def handle(self, *args, **options):
if skip_socials:
print("Skipping posting to social media!")
else:
self.post_to_x(q.socials_text)
self.post_to_x()
self.post_to_bluesky(q.socials_text)
self.post_to_mastodon(q.socials_text)

def post_to_x(self, content):
def post_to_x(self):
content = "We just published a new question! Follow us on Bluesky @cppquiz.bsky.social or Mastodon @cppquiz@mastodon.online for updates. For obvious reasons, no longer post to Elon Musk's X."
print(f"Posting to X: '{content}'")
try:
secrets = self.read_secrets()

client = tweepy.Client(
consumer_key=secrets["consumer_key"], consumer_secret=secrets["consumer_secret"],
access_token=secrets["access_token"], access_token_secret=secrets["access_token_secret"],
)
response = client.create_tweet(
text=content
)
post_url = f"https://x.com/user/status/{response.data['id']}"
print(f"Posted {post_url}")
except Exception as e:
print(f"Failed to post '{content}' to X due to exception '{e}'")
sys.exit(1)
secrets = self.read_secrets()

client = tweepy.Client(
consumer_key=secrets["consumer_key"], consumer_secret=secrets["consumer_secret"],
access_token=secrets["access_token"], access_token_secret=secrets["access_token_secret"],
)
response = client.create_tweet(
text=content
)
post_url = f"https://x.com/user/status/{response.data['id']}"

def post_to_bluesky(self, content):
print(f"Posting to Bluesky: '{content}'")
Expand Down Expand Up @@ -90,7 +86,6 @@ def post_to_mastodon(self, content):
r = requests.post(url, data=params, headers=auth)
r.raise_for_status()


def read_secrets(self):
secrets_file = Path.home() / ".cppquiz-secrets.json"
with secrets_file.open() as f:
Expand Down

0 comments on commit 8544430

Please sign in to comment.