How To Load Test Your Node.js App Using K6

OK you have developed your Node.js application, ran unit tests, ran integration tests now what you should do? You should run a load test! right? In order to see if your application can handle the…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




My first Twitterbot

a saga of technical decisions

I made my first Twitterbot this month. A friend of mine had posted that they wished there was a bot that would retweet the president with the comment “Not a bot” every new tweet. Since I hadn’t made a bot before, I thought I’d tackle this.

You’ll need to set up an “app” with that Twitter account in order to get all of the access keys to make API requests. In the end, you should receive a Consumer Key (API Key) and Consumer Secret (API Secret) for the app and an Access Token, and Access Token Secret for your account.

After setting up my bot’s Twitter account, I had to decide how to do my script.

Here’s my initial thinking:

At this point, a lot of things fell into place. I realized in my sequential deployments of this script to various platforms that I didn’t need to store off the most recent tweet id- Twitter’s API is set up so that if you try to tweet the exact same thing more than once in a row, it will automatically block the repeat POST requests. No longer needing to store any tweet ids, I just needed a script that would regularly retweet the most recent tweet and Twitter would manage not posting duplicates for me.

So now I was only using the database for Sidekiq. Really, I felt like that and Sinatra, while lightweight, was a little overkill for a script that just needs to run every few minutes. So I re-wrote my script to be a simple while loop. For about a day, I keep it on my personal computer, running in the background, but I knew it’d be a lot nicer if I had a remote VM running the script for me. I didn’t need a whole PaaS.

There is not much else to my script except for retweeting; I have some ‘puts’ statements to let me know it’s still running and I log them to a file on my VM that I can check any time. There was a 24 hour period where the script fell on its face on the VM and I had to restart the script, so no tweets from that day were retweeted. But it’s going pretty well right now.

In the future I’m going to investigate paying for a container instead of a whole VM. I had to set up the environment on the VM by myself, ‘apt-get’-ing everything I needed but a simple docker image could have done the same thing for me. However, because the VM is small and cheap, I was ok with some extra set up at the time.

Add a comment

Related posts:

Is Tuesday the Middle Child of the Work Week?

A lot of people start counting down their work week beginning Sunday evening. With Game of Thrones off for the season, what do we we have to look forward to in order to get through the week? From…

The rona got us.

The last 72 hours have been surreal for myself, let alone a lot of people. Sports has taught me life lessons and honestly, it’s given me a lot of my friends near or far. In fact, I was just at a…

Incentives Drive Behavior

Hey guys! Chapter 3 of Naked Economics talks about the ways that incentives drive behavior. One of my points from my list of ten was that every regulation carries a cost, sometimes it’s worth it, and…