Last active
March 12, 2018 20:04
-
-
Save lucprincen/a38242a3c6dec24d52697164a07f351d to your computer and use it in GitHub Desktop.
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
const Twitter = require('twitter'); | |
const config = require('./config.js'); | |
const T = new Twitter(config); | |
//add week number support: | |
Date.prototype.getWeekNumber = function(){ | |
var d = new Date(Date.UTC(this.getFullYear(), this.getMonth(), this.getDate())); | |
var dayNum = d.getUTCDay() || 7; | |
d.setUTCDate(d.getUTCDate() + 4 - dayNum); | |
var yearStart = new Date(Date.UTC(d.getUTCFullYear(),0,1)); | |
return Math.ceil((((d - yearStart) / 86400000) + 1)/7) | |
}; | |
function postTweet(){ | |
const emoji = { 0: '0️⃣', 1: '1️⃣', 2: '2️⃣', 3: '3️⃣', 4: '4️⃣', 5: '5️⃣', 6: '6️⃣', 7: '7️⃣', 8: '8️⃣', 9: '9️⃣ '}; | |
const numbers = new Date().getWeekNumber().toString().split(''); | |
let weeknum = ''; | |
for( i = 0; i < numbers.length; i++ ){ | |
weeknum += emoji[ numbers[i] ]; | |
} | |
T.post( 'statuses/update', { | |
status: '@Logfather '+weeknum | |
}); | |
} | |
//run the code every week: | |
const week = 1000 * 60 * 60 * 24 * 7; | |
setInterval( postTweet, week ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment