Skip to content

Commit

Permalink
Fix tweeting (posting to X)
Browse files Browse the repository at this point in the history
This has been broken for a while
  • Loading branch information
knatten committed Sep 22, 2024
1 parent e5465a6 commit ff3c3d0
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions quiz/management/commands/auto_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ def tweet(self, content):
secrets_file = Path.home() / ".cppquiz-secrets.json"
with secrets_file.open() as f:
secrets = json.load(f)
auth = tweepy.OAuthHandler(secrets["consumer_key"], secrets["consumer_secret"])
auth.set_access_token(secrets["key"], secrets["secret"])
api = tweepy.API(auth)
api.update_status(content)

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
)
print(f"Posted https://twitter.com/user/status/{response.data['id']}")
except Exception as e:
print(f"Failed to tweet '{content}' due to exception '{e}'")
sys.exit(1)

0 comments on commit ff3c3d0

Please sign in to comment.