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:
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>Have 2 surprises for my 20k milestone!
— Tanishq Mathew Abraham (@iScienceLuvr) January 8, 2022
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
twitter_save_likes.py
and twitter_save_retweets.py
as tweet_id
.twitter_save.sh
during the duration of the giveaway which occassionally checks for new likes and retweets using the previously mentioned Python scripts.twitter_pick_winners.py
which picks the winners.This code was mainly based on Alexey Grigorev's great blog post but updated for the Twitter v2 API.