A Twitter bot, written in Python and running on a Raspberry Pi, that tweets randomly selected Voat post titles.
77 19 Jan 2016 21:19 by u/MotherfuckingSausage
I shared this with /v/whatever last week, but figured I'd share with you folks as well.
Twitter Account: RandomVoat
Github: RandomVoat - Tweeter Bot
I came across an old script I was using for a bot that would tweet randomly selected lines from a local .txt file, which I was dumping/scraping sentences into. I had some free time today and decided to re-purpose the script to keep me busy/for the hell of it. After adjusting some code and making some alterations to a ruby script a friend of mine wrote for scraping reddit, I pulled everything over to one of my Raspberry Pi's and set up a cron job to run the python and web scraper scripts at the top of every hour. I then set up the Tweeter account and created/authorized the app to said account. Thus, RandomVoat was born.
I'm currently working on another bot which will tweet the current top post on /v/all every few hours. If you would like to contribute to RandomVoat or any future stuff, feel free to drop me a line here or via above GitHub. If you come across any issues/bugs, you can submit them here.
After a week worth of tweets, I was seeing a lot of title duplications within some of the tweets, so I made some adjustments to the script that fetches and returns the random post titles to my main script today, which seem to have fixed the duplication issue (hopefully). In short, the changes made simply increase the size of the random pool of titles from 10 to 50, then I added a function which compares the 3 randomly selected strings to one another to check for duplications, returning True once no duplications are found. This function was then added to RandomTitles.main()'s run loop within an if statement (checking for True).
Anyway, hope you guys like it! If you'd like to contribute to this or any future projects (such as the one mentioned in Original Post), feel free to give me a shout. Any critiques/suggestions/improvements you guys/gals may have are very much welcomed and appreciated!
++ Update - 1/21 ++
First off, I'd like to thank everyone for the support, kind words and suggestions on this project so far! It means a lot to me and I've made some changes to the original concept based on the input you guys provided.
RandomVoat - (Twitter / Github)
A few of you had expressed the idea that snatching a random post from voat and posting that + link would be preferable - so I've adjusted the logic of my scripts to do just that. You can view the changes here.
I've also provided an example of a typical dump file that my scraper is returning here.
As you can see from the dump file, the ruby script is returning a post title on one line, then a link to that post's thread on the next. Currently, the ruby script is grabbing the current top post from the following subverses:
- /v/Showerthoughts
- /v/whatever
- /v/funny
- /v/politics
- /v/technology
- /v/programming
- /v/videos
- /v/pics
- /v/news
- /v/worldnews
- /v/science
My RandomTitles script then picks a title from the dump file (based on even number) and the line below, which holds the post thread URL. I plan on tweaking the logic of RandomTitles a tad to make things a bit more flexible/dynamic as far as accounting for an increase/reduction in the pool of subverses goes, as having to adjust my array (EVEN[]) each time I add/remove a subverse to the pool is not too efficient.
Another thing I'm noticing is that my scraper is catching some sticky posts from certain subverses, but I'm planning on finding a workaround for that today, so it hopefully won't be an issue for long.
TopPostOnVoat - (Twitter / Github)
I'm pleased to announce that my other project/bot - TopPostOnVoat - is now live!
This script, like RandomVoat, will run at the top of every hour (via crontab on RPi) and post the current top post on /v/all. To avoid reposting (which Twitter rejects anyway), the script won't reach status update (twitter post) if the top post hasn't changed since last tweet. Doing this was relatively easy, in which all I did was have it write the current post's href to a txt file (lastPost.txt) before posting, then on next run, the script will compare the value of my href variable to the string stored in lastPost. Passing check will tweet current post, failing dumps exception/error into log file.
Everything seems to be working as intended on this guy, but I'd love to hear any ideas or suggestions on ways I can improve it!
16 comments
4 u/tapeman 19 Jan 2016 22:34
this is actually way more funny than I thought it would be. great job.
1 u/MotherfuckingSausage [OP] 19 Jan 2016 22:50
Much appreciated, glad you like it!
3 u/PuttItOut 20 Jan 2016 01:36
Very interesting and random. I really like seeing things like this.
As others have mentioned a link would be great.
1 u/MotherfuckingSausage [OP] 20 Jan 2016 02:15
Thanks! I'm planning on adjusting it to link just one random (current) thread, based on the great feedback that everyone's given so far. I gave a slightly more in-depth answer to @NiklausTheNaked above.
3 u/PuttItOut 20 Jan 2016 02:21
Yeah, I looked at the script and noticed you were concatenating titles. I think originally I thought this was a bug. Makes linking a bit interesting.
Anyways, it's interesting and I'll be eyeing this.
0 u/MotherfuckingSausage [OP] 21 Jan 2016 18:54
Thought I'd let ya know, I've added an update to the OP regarding changes to RandomVoat and announcing TopPostOnVoat. Thanks again for your input and interest! :)
1 u/Official_ISIS 20 Jan 2016 00:03
Pretty nifty if I do say so myself.
0 u/MotherfuckingSausage [OP] 20 Jan 2016 00:07
Thanks!
1 u/NiklausTheNaked 20 Jan 2016 01:22
Neat project. It looks like you are putting multiple titles in the same tweet though:
Only looks that way on some of them.
1 u/MotherfuckingSausage [OP] 20 Jan 2016 02:06
Yeah, the original concept was to just smash up to 3 randomly selected strings (post titles) together, as it can produce some random/silly results. However, after the feedback I've received so far, I think I'll be adjusting it to just grab one random link from a dump file, which will be scraped and overwritten daily (at least once/day) to avoid linking to extremely old threads.
1 u/WhiteRonin 20 Jan 2016 01:25
Nice!
Can it scrape subs instead v/all?
0 u/MotherfuckingSausage [OP] 20 Jan 2016 02:10
Sure can! I can point it to pull from any subs.
It's currently pulling from: /v/Showerthoughts /v/TIL /v/whatever /v/funny
The way the ruby script operates, I can have it pull from many subs or just one.
0 u/JohnQCitizen 20 Jan 2016 07:11
I somehow expected more from FPH and Niggers.
0 u/Peynus 20 Jan 2016 09:41
My God, now v/niggers will probably be all they see xd