/twitter-giveaway-picker

Using the Twitter API to pick a giveaway winner

Primary LanguagePython

twitter-giveaway-picker

This is a quick 'n dirty codebase I use to pick winners for my Twitter giveaways. The giveaway instructions are that the 3 winners are randomly selected from those who liked and retweeted the giveaway tweet and follow me. The code saves the likes and retweets, and keeps randomly selecting winners, checking that the account follows me, until we have all three winners.

I used it for this giveaway:

Have 2 surprises for my 20k milestone!

First: A BOOK GIVEAWAY🎁

I'm autographing and giving 3 special color editions of @abhi1thakur's book "Approaching Almost Any Machine Learning Problem" (which I helped review)

To enter: like, RT this tweet & follow me by Jan 14th 10am PST pic.twitter.com/Hi5VQuGepU

— Tanishq Mathew Abraham (@iScienceLuvr) January 8, 2022
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

How it works

  1. I tweet the giveaway tweet.
  2. The ID of this tweet is put in twitter_save_likes.py and twitter_save_retweets.py as tweet_id.
  3. I run twitter_save.sh during the duration of the giveaway which occassionally checks for new likes and retweets using the previously mentioned Python scripts.
  4. At the end of the giveaway I run twitter_pick_winners.py which picks the winners.

Acknowledgements

This code was mainly based on Alexey Grigorev's great blog post but updated for the Twitter v2 API.