Last active
June 24, 2018 11:37
-
-
Save vcidst/a7cf8c768597812362d00d1f5c03dc57 to your computer and use it in GitHub Desktop.
Source for bombayraincalls // twitter bot that tweets if it is raining in Bombay // https://twitter.com/bombayraincalls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @bombayraincalls | |
// https://twitter.com/bombayraincalls | |
// tweets when it is raining in bombay | |
// generously supported by /r/Mumbai | |
// original source by dariusk | |
// https://github.com/dariusk/examplebot | |
// 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() { | |
var tweetText = "Yay, it is raining in BOM. There will be a rainbow out soon!"; | |
// post to twitter | |
T.post('statuses/update', { status: tweetText }, function(err, data, response) { | |
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().toJSON(); | |
if (weatherText.includes("Rain")) { | |
rainTwitter(); | |
console.log("I tweeted something at " + today); | |
} | |
}); | |
} | |
// 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