├── .gitignore ├── LICENSE ├── meduza.js ├── package-lock.json ├── package.json └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .idea 3 | .iml -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015-2018 Nikolay Solovyov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /meduza.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | // TODO: подписка на вечернюю медузу 4 | // TODO: стриминг 5 | // TODO: поиск 6 | // TODO: категории для английской версии 7 | 8 | const argv = require('yargs').argv; 9 | const color = require('cli-color'); 10 | 11 | let restler, moment, cheerio, html2text, wrap, readline; 12 | 13 | const gold = function(s) { 14 | return Meduza.settings.color ? color.xterm(215)(s) : s; 15 | }; 16 | const gray = function(s) { 17 | return Meduza.settings.color ? color.xterm(245)(s) : s; 18 | }; 19 | const dark = function(s) { 20 | return Meduza.settings.color ? color.xterm(237)(s) : s; 21 | }; 22 | const underline = function(s) { 23 | return Meduza.settings.color ? color.underline(s) : s; 24 | }; 25 | const bold = function(s) { 26 | return Meduza.settings.color ? color.bold.white(s) : s; 27 | }; 28 | const italic = function(s) { 29 | return Meduza.settings.color ? color.italic(s) : s; 30 | }; 31 | const center = function(s) { 32 | let lines = s.split('\n'); 33 | 34 | lines = lines.map(function(line) { 35 | const len = line.length; 36 | const paddingLength = parseInt((80 - len) / 2) + 1; 37 | const padding = (new Array(paddingLength)).join(' '); 38 | 39 | return padding + line; 40 | }); 41 | 42 | return lines.join('\n'); 43 | }; 44 | 45 | const urlRegex = new RegExp(new RegExp('(?:(?:https?|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))(?::\\d{2,5})?(?:/[^ \\f\\n\\r\\t\\v\​\u00a0\\u1680\​\u180e\\u2000-\\u200a\​\u2028\\u2029​\\u202f\\u205f\​\u3000\\]]*)?', 'g')); 46 | const bracketsRegex = new RegExp('\\[\\d+\\]', 'g'); 47 | 48 | const replaceUrls = function(html, arr) { 49 | return html.replace(urlRegex, function(link) { 50 | let isSpaned = false; 51 | if (link.search('"> -1) isSpaned = true; 52 | arr.push(link.replace('"> 30) { 129 | settings.number = 30; 130 | } 131 | 132 | const chronos_arr = Object.keys(this.chronos); 133 | 134 | for (let i = 0, l = argv._.length; i < l; i++) { 135 | if (argv._[i] === 'en') { 136 | settings.locale = argv._[i]; 137 | } else if (argv._[i].search('meduza.io/') > -1) { 138 | settings.directUrl = argv._[i]; 139 | } else if (argv._[i].search(':') > -1) { 140 | settings.show = argv._[i]; 141 | } else if (chronos_arr.indexOf(argv._[i]) > -1) { 142 | settings.chrono = argv._[i]; 143 | } 144 | } 145 | 146 | this.settings = settings; 147 | }, 148 | 149 | checkUpdates: function() { 150 | const _this = this; 151 | 152 | restler 153 | .get('https://raw.githubusercontent.com/ozio/meduza/master/package.json') 154 | .on('complete', function(data) { 155 | const currentVersion = require('./package.json').version; 156 | const lastVersion = JSON.parse(data).version; 157 | 158 | _this.spinnerHide(); 159 | 160 | if (currentVersion !== lastVersion) { 161 | console.log(_this.showLine('', dark)); 162 | console.log(color.red(center(`${_this.translate('Установленная версия')}: ${currentVersion}, ${_this.translate('актуальная версия')}: ${lastVersion}.`))); 163 | console.log(color.red(center(_this.translate('Пожалуйста, обновите программу (npm update -g meduza).')))); 164 | console.log(_this.showLine('', dark)); 165 | console.log(''); 166 | } 167 | }); 168 | }, 169 | 170 | showHelp: function() { 171 | const help = ` 172 | Usage: ${underline(gold('meduza'))} [commands/options] 173 | 174 | Commands: ${gray('(you can combine every command with each other)')} 175 | 176 | meduza \tOutput latest news. 177 | meduza en \tOutput latest news from english version. 178 | meduza