DEV Community

Twitter bot in 17 lines of code

Martin Malinowski on March 27, 2018

A few months ago I posted how to "create a twitter bot in 3 minutes". Since then Twitter API changed so I decided that its time for an update. I ...
Collapse
 
mrm8488 profile image
Manuel Romero • Edited

Hi, Martin! First of all, congrats for the post!
It would be good to handle the error on: "stream.on('error'...". If you throw the error as it is the upper function, the error will reach the event loop and the application will crash.
A quick solution would be:

stream.on("error", error => console.error(error));
Collapse
 
notfakedev profile image
Martin Malinowski

thanks! my only concern would be, if we have the app still running after for example reaching API requests limit for the next 10 hours, are we risking Twitter ban? I think we would also have to implement counter+timer. What you think?

Collapse
 
mrm8488 profile image
Manuel Romero

It depends on the Twitter API. But you are not requesting anything to its REST API. You are subscribed to an event. So maybe they manage how much data they can give you.

Thread Thread
 
notfakedev profile image
Martin Malinowski • Edited

right, there are limits but its something like 1% above threshold, I updated the post, cheers!

Collapse
 
jaswdr profile image
Jonathan André Schweder

You know that is not 17 lines of code because you need to add the dependencies, but what matter ¯_(ツ)_/¯

Collapse
 
notfakedev profile image
Martin Malinowski

let's not be that strict 😅