Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions quiz/management/commands/auto_publish.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import sys
import traceback
import requests
import datetime
from pathlib import Path
Expand All @@ -19,18 +20,36 @@ def add_arguments(self, parser):

def handle(self, *args, **options):
skip_socials = options["skip_socials"]
had_failure = False

for q in Question.objects.filter(state='SCH', publish_time__lte=timezone.now()):
print(f"Publishing question {q}")
q.state = 'PUB'
q.save()
if (q.socials_text):
if q.socials_text:
if skip_socials:
print("Skipping posting to social media!")
else:
self.post_to_x()
self.post_to_bluesky(q.socials_text)
self.post_to_mastodon(q.socials_text)
had_failure |= self.post_to_socials(q.socials_text)

if had_failure:
sys.exit(1)

def post_to_socials(self, content):
platforms = [
("X", self.post_to_x),
("Bluesky", lambda: self.post_to_bluesky(content)),
("Mastodon", lambda: self.post_to_mastodon(content)),
]
had_failure = False
for name, post in platforms:
try:
post()
except Exception:
had_failure = True
print(f"Failed to post question to {name}:", file=sys.stderr)
traceback.print_exc()
return had_failure

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."
Expand Down
Loading