These scripts work together to allow you to select a specific number of winners for a twitter drawing.
It uses a tweet ID to find the retweeters and followers of that account to determine eligable winners. It also accepts the number of winners to select.
- Download both files to the same directory
- Open a terminal in that directory
chmod +x ./twitter-*
# makes the files executable./twitter-drawing.sh <twitter-id> <number-of-winners>
Results will be displayed as:
[
<screen_name>,
<screen_name>,
]
Unforunately, this is not perfect. Given that I wrote it in an 1.5 hours I didn't expect it to be.
Here are the known issues:
Potentially returns less results than requested This is not actually an error in the logic as it is more an error in the final conversion of id to handle and the twitter API returns an unknown response for the user ID.
(On a more nitpicky note) I am really not a fan of having to use two different scripts for this but twurl made the API calls so easy and JavaScript made the filter and random so easy that I had to use what worked simple and easy for the occasion.
Maybe if I do another one of these I will pick a single language and stick to it. Maybe someone in the comments will show me how terrible this all is and write me a whole new one, until then, this worked well enough for me.
It pulls creates files in local temp directories that include a list of followers and retweeters of based on the tweet id passed in.
Then it passed it that data over to the js script which will create a Set
using randomly generated indexes based on the length of the list. That is then console logged to be picked back up in the parent shell script.
The list is then passed back to twitter to convert the IDs to handles.