What is this?
@unsuretrump is an extremely simple Twitterbot that tweets out Donald Trump's tweets but replaces all the question marks with exclamation points. It's been running consistently since 2015. The simple punctuation change completely changes meaning of the original statement. It uses Trump's own words to question his opinions & persona.
It's a completely brilliant and simple piece of art that was in no way my idea.
Working with Jesse
Jesse has been one of my best friends since we met in college over a decade ago. He has an almost supernatural talent to generate content that will connect with people on the internet. He's also hilarious.
Jesse came to me with the concept of @unsuretrump fully formed. He knew exactly how he wanted the bot to work; which tweets to parse, which ones to skip. He just couldn't write the code. So, that's why he asked me for help. He's the artist, I'm just the one making it work.
How do you make a Twitterbot?
Unfortunately when Jesse asked me to build this for him, I had no idea how to make a "bot." I knew understood their basic concept and I had done some experimental work with the Twitter API, but this was a whole other thing! After looking around the internet and realizing making a Twitter bot was something very easy to make, I knew this project was doable.
Changing a single character in only 170 lines of code!
Because I wanted to run this on my old GoDaddy hosting account, it had to be written in PHP. Which I love. Don't @ me. James Mallison made a great Twitter API wrapper for php that I used. This also meant that I couldn't use Twitter's realtime API because a GoDaddy hosting account is not set up for that. So, I would have to check for new tweets every few seconds. I didn't know how to do that yet, so I came up with the actual script first.
Every time the script ran, I would check to see if they're were any new tweets since the last time the script ran. If there were, I wrote this really long
if statement to check if it's not a retweet or an @reply which looks like this:
if($tt['in_reply_to_user_id'] == NULL && strpos($tweet_exploded, '"@') === false && $tweet_exploded !== 'RT' && !(in_array($tweet_id,$oldArray)))
THEN, I looped through each word in the tweet to see if it had a
!. If it did, we tweeted it out. Pretty simple right? I also did some weird things with .txt files and stuff that I probably wouldn't have done in retrospect. You live & learn right?
Now that my script processes the tweets on runtime, I was basically done right? Nope. How do you make a php script run automatically?!?!
I have no understanding of how servers work
The obvious answer is a cron job.
This is something I was too scared to try / never heard of when I first started this project. So, I found some script that showed me how to ping a URL on a timer with Google Scripts! Done! Every 15 minutes we hit the php file and it runs the script and processes any new tweets from Donald Trump. There's a secret url parameter, so if anyone else figures out the full url, they get blocked if they don't have the right parameter. Is this a stupid way of running a timer job? Yes, but it works.
Do people like our little bot?
When we made the @unsuretrump twitter bot back in 2015, Donald Trump was starting out his presidential campaign. A lot of people thought this campaign was ludicrous and were already taking to mocking Trump. So, our expectation for the bot was: "People will think it's funny and follow it. Then after Trump loses the primary, people will unfollow it and everyone will forget it existed."
Lucky for us, and some would say unlucky for the world, Donald Trump was elected president and has decided to use his Twitter account as the unfiltered voice of the president of the united states. His Twitter is more relevant than ever. And his tweets are FULL of great exclamation points.
AMERICA FIRST?— UnsureDonaldTrump (@UnsureTrump) November 21, 2018
We have 7,500 followers and the bot's tweets regularly get decent amounts of likes & retweets. I consider it a success! (success?).
I would like to completely re-write the back-end of this. The code is trash basically. Re-write it and have it run on a cron job.
What I Learned
- Twitter API
- using txt files as fake database
- tons of PHP
- Google Scripts