Skip to content

Instantly share code, notes, and snippets.

@vcidst
Created June 10, 2020 04:48
Show Gist options
  • Save vcidst/2dea0c84ecc8bb83881b8a17b202d3ab to your computer and use it in GitHub Desktop.
Save vcidst/2dea0c84ecc8bb83881b8a17b202d3ab to your computer and use it in GitHub Desktop.
Bombay Rain Calls - A twitter bot for Mumbai Rain Alerts
// Our Twitter library
var Twit = require('twit');
var weather = require('weather-js');
// We need to include our configuration file
var T = new Twit(require('./config.js'));
// this function posts to twitter that it is rainy
function rainTwitter(today) {
var tweets = [
'Yay, it is raining in in #bombay! There will be a #rainbow out soon! #rain #mumbai',
'Our beloved monsoon overlords are here as it #rains in the city #mumbairain',
'Pouring rats and dogs in #mumbai #bombayrains',
'dihydrogen monoxide falling from the skies! Stay safe all of you! #raininginbombay',
'I tweet when it is raining in #Mumbai',
'The sweet smell of rain, petrichor! #mumbairains',
'Time to take out your books, make a cup of coffee and sit by the window. This #rain is going to last a while',
'Greetings, human. Good thing you\'r carrying an umbrella #raininginmumbai',
'Another rainy and wet day for the city of dreams #mumbairains',
'I am expecting to tweet all the way for next three months #dotherainseverstop',
'Rain alert! Oh boy, the traffic is going to get mad! #bombayrain',
'I like to walk in the rain so that no one can see my tears #emobot #raininginmumbai',
'oh boy, everyone in the local is going to be soo wet if this lasts any more #mumbairain',
'Whoever is going to work today, please drive safe in the rain. #consideratebot #mumbairain',
'Ya how much rain to make Dadar into sion lake is what I\'m aksing #rmumbai #rains',
'folks do you see the rain, like itna saara rain! how even! #mumbairains',
'Another day, lots of rain, Mumbai is flooded, lots of pain.\n Just the usual Mumbai Monsoon Bane.',
'From dusk till dawn,lots of rain thunder \n Its a tale forever told, from yonder \n Its the season of rain, \n For the city, its a bane \n For we pay the price for civic blunders',
'The sights, the sounds of rain \n Pitter Patter of the drops, \n Remind of a distant time, a distant someone, perhaps.'
];
var randomNumber = Math.floor(Math.random()*tweets.length);
var tweetText = tweets[randomNumber] + " at " + today
// post to twitter
T.post('statuses/update', { status: tweetText }, function(err, data, response) {
if(data.created_at != null) console.log(data.created_at);
else console.log(data);
})
}
// checks if it is raining in bombay
function IsItRainingInBombay() {
// async functin to get weather
weather.find({search: 'Mumbai, India', degreeType:'C'}, function(error, result) {
if(error) console.log(error);
var weatherText = result[1].current.skytext;
var today = new Date();
var now = today.getHours() + ":" + today.getMinutes();
if (weatherText.includes("Rain")) {
rainTwitter(now);
console.log("I tweeted something at " + now);
} else {
console.log("It isn't raining right now but I'm alive!");
}
});
}
// check the weather as we run the program...
IsItRainingInBombay();
// ...and then every hour after that. Time here is in milliseconds, so
// 1000 ms = 1 second, 1 sec * 60 = 1 min, 1 min * 60 = 1 hour --> 1000 * 60 * 60
setInterval(IsItRainingInBombay, 1000 * 60 * 60);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment