├── .gitignore ├── config.example.js ├── README.md ├── package.json ├── index.js └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .vscode/ 3 | /.idea/ 4 | /config.js 5 | /config.js* 6 | /a.js 7 | out* -------------------------------------------------------------------------------- /config.example.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Config 3 | * @authors RalfZ (ralfz.zhang@gmail.com) 4 | * @date 2017-05-01 17:32:42 5 | * @version 1.0.0 6 | */ 7 | 8 | module.exports = { 9 | headers: {}, 10 | dataString: 'comment=11&', 11 | } 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 豆瓣大笨钟 2 | 3 | 人人大笨钟 豆瓣复刻版 4 | 5 | 整点报时器 6 | 7 | https://www.douban.com/people/160931760/ 8 | 9 | 10 | 11 | ## 致谢 12 | - http://page.renren.com/renren_big_ben 13 | - https://github.com/DreaminginCodeZH/DoubanYearProgress 14 | 15 | ## License 16 | MIT -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "douban-guang", 3 | "version": "1.0.0", 4 | "description": "豆瓣大笨钟", 5 | "main": "index.js", 6 | "author": "RalfZ", 7 | "license": "MIT", 8 | "dependencies": { 9 | "moment-timezone": "^0.5.35", 10 | "node-schedule": "^1.2.1", 11 | "request": "^2.81.0", 12 | "request-promise": "^4.2.0" 13 | }, 14 | "scripts": { 15 | "start": "node index.js", 16 | "test": "node a.js" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 大笨钟 3 | * @authors RalfZ (ralfz.zhang@gmail.com) 4 | * @date 2017-05-01 17:39:51 5 | * @version 1.0.0 6 | */ 7 | const rp = require('request-promise'); 8 | const ns = require('node-schedule'); 9 | const mt = require('moment-timezone'); 10 | 11 | const config = require('./config.js'); 12 | 13 | const postMessage = (str) => { 14 | const dataStringGen = (str) => { 15 | return config.dataString.replace(/(.*comment=)(.*)(&.*)/, (_, p1, p2, p3) => { 16 | return `${p1}${str}${p3}` 17 | }); 18 | }; 19 | 20 | const options = { 21 | url: 'https://www.douban.com/', 22 | method: 'POST', 23 | headers: config.headers, 24 | gzip: true, 25 | body: dataStringGen(str), 26 | }; 27 | 28 | return rp(options); 29 | } 30 | 31 | function postBroadcast(text) { 32 | console.log('-->', new Date(), 'run postBroadcast.') 33 | postMessage(text).then(_ => { 34 | console.log('---->', new Date(), 'postBroadcast Success.') 35 | }).catch(err => { 36 | console.log('----> catch event.'); 37 | }) 38 | } 39 | 40 | function getText() { 41 | const now = mt().tz('Asia/Shanghai') 42 | const yearStart = mt(now).startOf('year'); 43 | const yearEnd = mt(yearStart).add(1, 'year'); 44 | let progress = Math.round(100000 * now.diff(yearStart) / yearEnd.diff(yearStart)) / 1000; 45 | // console.log('p', process) 46 | let hour = +now.format('HH') 47 | if (hour === 0) { 48 | hour = 24 49 | } 50 | let year = now.format('YYYY'); 51 | if (progress === 0) { // 处理新年结束 52 | year = year - 1; 53 | progress = 100; 54 | } 55 | let text = '咣!'.repeat(hour) + `豆瓣大笨钟提醒您:北京时间${hour}点整,${year}年已悄悄溜走${progress}%。` 56 | return text; 57 | } 58 | 59 | function run() { 60 | postBroadcast('尝试重启中……'); 61 | let i = 0; 62 | ns.scheduleJob('0 * * * *', () => { 63 | i++; 64 | console.log('>', new Date(), 'posting hour', i); 65 | console.log('> Text: ', getText()) 66 | postBroadcast(getText()) 67 | }) 68 | 69 | // screen detach 无任务 1 小时候后不执行 schedule,添加每十分钟唤醒 70 | ns.scheduleJob('30 */10 * * * *', () => { 71 | i++; 72 | console.log(new Date(), 'posting min', i); 73 | }) 74 | } 75 | 76 | run(); 77 | -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | "ajv@^6.12.3": 6 | "version" "6.12.4" 7 | dependencies: 8 | "fast-deep-equal" "^3.1.1" 9 | "fast-json-stable-stringify" "^2.0.0" 10 | "json-schema-traverse" "^0.4.1" 11 | "uri-js" "^4.2.2" 12 | 13 | "asn1@~0.2.3": 14 | "version" "0.2.4" 15 | dependencies: 16 | "safer-buffer" "~2.1.0" 17 | 18 | "assert-plus@^1.0.0", "assert-plus@1.0.0": 19 | "resolved" "http://registry.npm.taobao.org/assert-plus/download/assert-plus-1.0.0.tgz" 20 | "version" "1.0.0" 21 | 22 | "asynckit@^0.4.0": 23 | "resolved" "http://registry.npm.taobao.org/asynckit/download/asynckit-0.4.0.tgz" 24 | "version" "0.4.0" 25 | 26 | "aws-sign2@~0.7.0": 27 | "version" "0.7.0" 28 | 29 | "aws4@^1.8.0": 30 | "version" "1.10.1" 31 | 32 | "bcrypt-pbkdf@^1.0.0": 33 | "version" "1.0.2" 34 | dependencies: 35 | "tweetnacl" "^0.14.3" 36 | 37 | "bluebird@^3.5.0": 38 | "version" "3.7.2" 39 | 40 | "caseless@~0.12.0": 41 | "resolved" "http://registry.npm.taobao.org/caseless/download/caseless-0.12.0.tgz" 42 | "version" "0.12.0" 43 | 44 | "combined-stream@^1.0.6", "combined-stream@~1.0.6": 45 | "version" "1.0.8" 46 | dependencies: 47 | "delayed-stream" "~1.0.0" 48 | 49 | "core-util-is@1.0.2": 50 | "version" "1.0.2" 51 | 52 | "cron-parser@^2.7.3": 53 | "version" "2.16.3" 54 | dependencies: 55 | "is-nan" "^1.3.0" 56 | "moment-timezone" "^0.5.31" 57 | 58 | "dashdash@^1.12.0": 59 | "resolved" "http://registry.npm.taobao.org/dashdash/download/dashdash-1.14.1.tgz" 60 | "version" "1.14.1" 61 | dependencies: 62 | "assert-plus" "^1.0.0" 63 | 64 | "define-properties@^1.1.3": 65 | "version" "1.1.3" 66 | dependencies: 67 | "object-keys" "^1.0.12" 68 | 69 | "delayed-stream@~1.0.0": 70 | "resolved" "http://registry.npm.taobao.org/delayed-stream/download/delayed-stream-1.0.0.tgz" 71 | "version" "1.0.0" 72 | 73 | "ecc-jsbn@~0.1.1": 74 | "version" "0.1.2" 75 | dependencies: 76 | "jsbn" "~0.1.0" 77 | "safer-buffer" "^2.1.0" 78 | 79 | "extend@~3.0.2": 80 | "version" "3.0.2" 81 | 82 | "extsprintf@^1.2.0", "extsprintf@1.3.0": 83 | "version" "1.3.0" 84 | 85 | "fast-deep-equal@^3.1.1": 86 | "version" "3.1.3" 87 | 88 | "fast-json-stable-stringify@^2.0.0": 89 | "version" "2.1.0" 90 | 91 | "forever-agent@~0.6.1": 92 | "resolved" "http://registry.npm.taobao.org/forever-agent/download/forever-agent-0.6.1.tgz" 93 | "version" "0.6.1" 94 | 95 | "form-data@~2.3.2": 96 | "version" "2.3.3" 97 | dependencies: 98 | "asynckit" "^0.4.0" 99 | "combined-stream" "^1.0.6" 100 | "mime-types" "^2.1.12" 101 | 102 | "getpass@^0.1.1": 103 | "resolved" "http://registry.npm.taobao.org/getpass/download/getpass-0.1.7.tgz" 104 | "version" "0.1.7" 105 | dependencies: 106 | "assert-plus" "^1.0.0" 107 | 108 | "har-schema@^2.0.0": 109 | "version" "2.0.0" 110 | 111 | "har-validator@~5.1.3": 112 | "version" "5.1.5" 113 | dependencies: 114 | "ajv" "^6.12.3" 115 | "har-schema" "^2.0.0" 116 | 117 | "http-signature@~1.2.0": 118 | "version" "1.2.0" 119 | dependencies: 120 | "assert-plus" "^1.0.0" 121 | "jsprim" "^1.2.2" 122 | "sshpk" "^1.7.0" 123 | 124 | "is-nan@^1.3.0": 125 | "version" "1.3.0" 126 | dependencies: 127 | "define-properties" "^1.1.3" 128 | 129 | "is-typedarray@~1.0.0": 130 | "resolved" "http://registry.npm.taobao.org/is-typedarray/download/is-typedarray-1.0.0.tgz" 131 | "version" "1.0.0" 132 | 133 | "isstream@~0.1.2": 134 | "resolved" "http://registry.npm.taobao.org/isstream/download/isstream-0.1.2.tgz" 135 | "version" "0.1.2" 136 | 137 | "jsbn@~0.1.0": 138 | "resolved" "http://registry.npm.taobao.org/jsbn/download/jsbn-0.1.1.tgz" 139 | "version" "0.1.1" 140 | 141 | "json-schema-traverse@^0.4.1": 142 | "version" "0.4.1" 143 | 144 | "json-schema@0.2.3": 145 | "resolved" "http://registry.npm.taobao.org/json-schema/download/json-schema-0.2.3.tgz" 146 | "version" "0.2.3" 147 | 148 | "json-stringify-safe@~5.0.1": 149 | "resolved" "http://registry.npm.taobao.org/json-stringify-safe/download/json-stringify-safe-5.0.1.tgz" 150 | "version" "5.0.1" 151 | 152 | "jsprim@^1.2.2": 153 | "version" "1.4.1" 154 | dependencies: 155 | "assert-plus" "1.0.0" 156 | "extsprintf" "1.3.0" 157 | "json-schema" "0.2.3" 158 | "verror" "1.10.0" 159 | 160 | "lodash@^4.17.19": 161 | "version" "4.17.20" 162 | 163 | "long-timeout@0.1.1": 164 | "resolved" "http://registry.npm.taobao.org/long-timeout/download/long-timeout-0.1.1.tgz" 165 | "version" "0.1.1" 166 | 167 | "mime-db@1.44.0": 168 | "version" "1.44.0" 169 | 170 | "mime-types@^2.1.12", "mime-types@~2.1.19": 171 | "version" "2.1.27" 172 | dependencies: 173 | "mime-db" "1.44.0" 174 | 175 | "moment-timezone@^0.5.31", "moment-timezone@^0.5.35": 176 | "integrity" "sha512-72j3aNyuIsDxdF1i7CEgV2FfxM1r6aaqJyLB2vwb33mXYyoyLly+F1zbWqhA3/bVIoJ4szlUoMbUnVdid32NUQ==" 177 | "resolved" "https://registry.npmmirror.com/moment-timezone/-/moment-timezone-0.5.43.tgz" 178 | "version" "0.5.43" 179 | dependencies: 180 | "moment" "^2.29.4" 181 | 182 | "moment@^2.29.4": 183 | "integrity" "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==" 184 | "resolved" "https://registry.npmmirror.com/moment/-/moment-2.29.4.tgz" 185 | "version" "2.29.4" 186 | 187 | "node-schedule@^1.2.1": 188 | "version" "1.3.2" 189 | dependencies: 190 | "cron-parser" "^2.7.3" 191 | "long-timeout" "0.1.1" 192 | "sorted-array-functions" "^1.0.0" 193 | 194 | "oauth-sign@~0.9.0": 195 | "version" "0.9.0" 196 | 197 | "object-keys@^1.0.12": 198 | "version" "1.1.1" 199 | 200 | "performance-now@^2.1.0": 201 | "version" "2.1.0" 202 | 203 | "psl@^1.1.28": 204 | "version" "1.8.0" 205 | 206 | "punycode@^2.1.0", "punycode@^2.1.1": 207 | "version" "2.1.1" 208 | 209 | "qs@~6.5.2": 210 | "version" "6.5.2" 211 | 212 | "request-promise-core@1.1.4": 213 | "version" "1.1.4" 214 | dependencies: 215 | "lodash" "^4.17.19" 216 | 217 | "request-promise@^4.2.0": 218 | "version" "4.2.6" 219 | dependencies: 220 | "bluebird" "^3.5.0" 221 | "request-promise-core" "1.1.4" 222 | "stealthy-require" "^1.1.1" 223 | "tough-cookie" "^2.3.3" 224 | 225 | "request@^2.34", "request@^2.81.0": 226 | "version" "2.88.2" 227 | dependencies: 228 | "aws-sign2" "~0.7.0" 229 | "aws4" "^1.8.0" 230 | "caseless" "~0.12.0" 231 | "combined-stream" "~1.0.6" 232 | "extend" "~3.0.2" 233 | "forever-agent" "~0.6.1" 234 | "form-data" "~2.3.2" 235 | "har-validator" "~5.1.3" 236 | "http-signature" "~1.2.0" 237 | "is-typedarray" "~1.0.0" 238 | "isstream" "~0.1.2" 239 | "json-stringify-safe" "~5.0.1" 240 | "mime-types" "~2.1.19" 241 | "oauth-sign" "~0.9.0" 242 | "performance-now" "^2.1.0" 243 | "qs" "~6.5.2" 244 | "safe-buffer" "^5.1.2" 245 | "tough-cookie" "~2.5.0" 246 | "tunnel-agent" "^0.6.0" 247 | "uuid" "^3.3.2" 248 | 249 | "safe-buffer@^5.0.1", "safe-buffer@^5.1.2": 250 | "version" "5.2.1" 251 | 252 | "safer-buffer@^2.0.2", "safer-buffer@^2.1.0", "safer-buffer@~2.1.0": 253 | "version" "2.1.2" 254 | 255 | "sorted-array-functions@^1.0.0": 256 | "version" "1.2.0" 257 | 258 | "sshpk@^1.7.0": 259 | "version" "1.16.1" 260 | dependencies: 261 | "asn1" "~0.2.3" 262 | "assert-plus" "^1.0.0" 263 | "bcrypt-pbkdf" "^1.0.0" 264 | "dashdash" "^1.12.0" 265 | "ecc-jsbn" "~0.1.1" 266 | "getpass" "^0.1.1" 267 | "jsbn" "~0.1.0" 268 | "safer-buffer" "^2.0.2" 269 | "tweetnacl" "~0.14.0" 270 | 271 | "stealthy-require@^1.1.1": 272 | "version" "1.1.1" 273 | 274 | "tough-cookie@^2.3.3", "tough-cookie@~2.5.0": 275 | "version" "2.5.0" 276 | dependencies: 277 | "psl" "^1.1.28" 278 | "punycode" "^2.1.1" 279 | 280 | "tunnel-agent@^0.6.0": 281 | "resolved" "http://registry.npm.taobao.org/tunnel-agent/download/tunnel-agent-0.6.0.tgz" 282 | "version" "0.6.0" 283 | dependencies: 284 | "safe-buffer" "^5.0.1" 285 | 286 | "tweetnacl@^0.14.3", "tweetnacl@~0.14.0": 287 | "resolved" "http://registry.npm.taobao.org/tweetnacl/download/tweetnacl-0.14.5.tgz" 288 | "version" "0.14.5" 289 | 290 | "uri-js@^4.2.2": 291 | "version" "4.2.2" 292 | dependencies: 293 | "punycode" "^2.1.0" 294 | 295 | "uuid@^3.3.2": 296 | "version" "3.4.0" 297 | 298 | "verror@1.10.0": 299 | "version" "1.10.0" 300 | dependencies: 301 | "assert-plus" "^1.0.0" 302 | "core-util-is" "1.0.2" 303 | "extsprintf" "^1.2.0" 304 | --------------------------------------------------------------------------------