Last active
May 4, 2017 08:44
-
-
Save hibiyasleep/a29a1099147733d9d1e526d6671fa9c9 to your computer and use it in GitHub Desktop.
calcium-tweet
This file contains hidden or 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
| #!/usr/bin/env node | |
| 'use strict' | |
| const calcium = require('calcium') | |
| const moment = require('moment') | |
| const fs = require('fs') | |
| const T = require('twit') | |
| const rc = JSON.parse(fs.readFileSync('/home/hibiya/.calciumrc').toString()) | |
| const SAT = moment('2016-11-16 08:10') | |
| let d = new Date() | |
| let today = d.getDate() | |
| let hour = d.getHours() | |
| // 0 6 12 18 +0 | |
| // | | | | | | |
| // ============ lunch | |
| // ====== dinner | |
| // ===== lunch (do date+=1, or do not tweet in this time) | |
| let type = (hour <= 12 || 18 < hour)? 'lunch' : 'dinner' | |
| let typeL = { | |
| lunch: '점심', | |
| dinner: '저녁' | |
| }[type] | |
| const getFeature = function(account, feature) { | |
| return account.feature && account.feature.indexOf(feature) !== -1 | |
| } | |
| for(let id in rc.accounts) { | |
| let account = rc.accounts[id] | |
| let t = new T(account.key) | |
| if(account.timesIn && account.timesIn.indexOf(hour) == -1) | |
| continue | |
| calcium.get(account.school, (e, d) => { | |
| let tweet = '' | |
| let now | |
| let m = moment() | |
| if(e) | |
| return console.error(e) | |
| if(!d[today] || !d[today][type]) | |
| return | |
| now = d[today][type] | |
| if(getFeature(account, 'private')) | |
| tweet += `@_ @${id} ` | |
| if(getFeature(account, 'gosam')) | |
| tweet += `[${moment(SAT.diff(moment())).format("DDD일 H시간 m분 s초")} ${typeL}]` | |
| else | |
| tweet += `[${m.format('M월 D일')} ${typeL}] ${hour}` | |
| tweet += '\n' | |
| if(account.filter) { | |
| let filter = new RegExp(account.filter, 'gi') | |
| now = now.map( m => m.replace(filter, '') ) | |
| } | |
| tweet += now.join('\n') | |
| if(tweet.length > 140) { | |
| tweet = `${tweet.slice(0, 132)}..\n(${now.length}개)` | |
| } | |
| t.post('statuses/update', { | |
| status: tweet, | |
| in_reply_to_status_id: account.replyTo || '' | |
| }, (e, d) => { | |
| if(e) console.error(e) | |
| }) | |
| }) | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
늦어서 죄송합니다. 설명을 위해 YAML 형식으로 작성해뒀으며, 필수가 아닌 값은 모두 선택적입니다.