Developing a Twitter bot that lets me watch Youtube videos on random!

I have been getting back to building bots. I think bots are beautiful. Bots are the future. I just finished watching Altered Carbon first Season on Netflix and the Matrix-like world reminded me of how close we are to AI taking over. But I am getting ahead of myself.




This post is going to be a part of a series of things I am working on with my bot. I'm having fun. My bot is listening to mentions at @nWriterdotcom. Currently I am filtering out any other tweets that do not have the hashtag (#youtubeme) so I can identify different sources of automated tweets(There's a lot).  Right now my bot does this :

1. Listen to mentions containing hashtag #youtubeme
2. Collect public username of source twitter account
3. Generate a random youtube video link with its full information.
4. Bundle it all together into one sentence and tweet back at the source account.
5. Tells the user(me) what it tweeted.

For 1, 2 and 4, I am using this npm package called twit. I had used this package before when I worked on my first experimental bot. It's simple, fairly easy to use and comes with built-in callbacks. I bundled everything I needed to work with from Twitter API in tweet.js that has three functions as of now :-
>tweetWrite  = pass one string argument to post as tweet
>tweetStream = pass a keyword to track in user stream. In my case I pass nWriterdotcom and filter out any tweet that doesn't contain #youtubeme.
>tweetSearch = search twitter for a given keyword/hashtag

Of course for this project I need not use the third function. I have been using it for other projects and would enjoy explaining in subsequent blog posts.




For generating a random youtube video link I used this another package called youtube-link-generator. All it needs is a youtube account OAuth key and it will retrieve everything from Youtube API. I am hoping I can use that information for multitude of other projects I have in my mind.

So that's it. I deploy it on my Raspberry Pi home server and refresh twitter stream node every thirty minutes using crontab, just to avoid any errors. I tested it from my personal account and it worked like a charm. Now using it to watch random youtube videos whenever I feel bored with the same content over and over again.

Comments

Popular posts from this blog

Building a local weather station using Raspberry pi W and Arduino Nano || Serial communication over Bluetooth HC-05 module

Youtube not working in Vianet NetTV? Here's how you can fix it

Building a news app in react-native using Expo and Express on the Node.js server