├── .gitignore ├── lib ├── cmd.js ├── cachedText.js ├── getRes.js └── parse.js ├── README.md ├── package.json └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /lib/cmd.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | require('./getRes.js')(); 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | A special command-line edition of the [Quartz Daily Brief](https://ssl.qz.com/brief), made for [SRCCON](http://srccon.org/) attendees 2 | 3 | Install like this: 4 | 5 | `npm install -g srccon-brief` 6 | 7 | Run like this: 8 | 9 | `srccon-brief` 10 | -------------------------------------------------------------------------------- /lib/cachedText.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | intro: 'Hello, SRCCON attendees!', 3 | outro: 'Our best wishes for an awesome conference.\n\n Please send any resumes, conference intrigue, and taco recipes to things@qz.com. \n\nYou can follow us on Twitter at @nsonnad, @stimply, and @YAN0 or apply for job to come work with us as a reporter (who codes) or a web applications developer.', 4 | footer: 'You\'re reading the SRCCON edition of the daily brief. It was written, designed, and coded by Nikhil Sonnad, Sam Williams, David Yanofsky.' 5 | }; 6 | 7 | -------------------------------------------------------------------------------- /lib/getRes.js: -------------------------------------------------------------------------------- 1 | var http = require('http'); 2 | var parseRes = require('./parse'); 3 | 4 | var req = { 5 | host: 'api.qz.com', 6 | path: '/0/things/srccon/dailyBrief' 7 | }; 8 | 9 | function getStream (res) { 10 | var str = ''; 11 | 12 | res.on('data', function (chunk) { 13 | str += chunk; 14 | }); 15 | 16 | res.on('error', function (err) { 17 | console.error(err); 18 | }); 19 | 20 | res.on('end', function () { 21 | var json = JSON.parse(str); 22 | parseRes(json); 23 | }); 24 | } 25 | 26 | module.exports = function () { 27 | http.get(req, getStream); 28 | }; 29 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "srccon-brief", 3 | "version": "0.0.10", 4 | "description": "Quartz's daily brief on SRCCON, in your command line", 5 | "main": "./index.js", 6 | "bin": { 7 | "srccon-brief": "./lib/cmd.js" 8 | }, 9 | "scripts": { 10 | "test": "echo \"Error: no test specified\" && exit 1" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git://github.com:Quartz/srccon-brief-cli.git" 15 | }, 16 | "keywords": [ 17 | "Quartz", 18 | "qz", 19 | "SRCCON" 20 | ], 21 | "author": "Quartz", 22 | "engines": { 23 | "node": ">=0.8.0" 24 | }, 25 | "license": "MIT", 26 | "dependencies": { 27 | "cheerio": "^0.17.0", 28 | "colors": "^0.6.2", 29 | "commander": "^2.3.0", 30 | "wordwrap": "0.0.2" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* 2 | ````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` 3 | ```````````***`````````````***```````***```````````***````````````******```````````************``````************```` 4 | ```````***********`````````***```````***``````````*****```````````**********```````************``````************```` 5 | `````***`````````***```````***```````***`````````***`***``````````***`````***``````````***```````````````````***````` 6 | ````***```````````***``````***```````***````````***```***`````````***``````***`````````***`````````````````***``````` 7 | ````***```````````***``````***```````***```````***`````***````````***********``````````***```````````````***````````` 8 | ````***``````***`***```````***```````***``````*************```````*********````````````***``````````````***`````````` 9 | `````***```````****`````````***`````***``````***************``````***````***```````````***````````````***```````````` 10 | ```````*************`````````*********``````***```````````***`````***`````***``````````***```````````************```` 11 | ```````````***`````**```````````***````````***`````````````***````***``````***`````````***```````````************```` 12 | ````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` 13 | */ 14 | 15 | require('./lib/getRes.js')(); 16 | -------------------------------------------------------------------------------- /lib/parse.js: -------------------------------------------------------------------------------- 1 | var colors = require('colors'); 2 | var prog = require('commander'); 3 | var wrap = require('wordwrap')(80); 4 | var cheerio = require('cheerio'); 5 | 6 | var cachedText = require('./cachedText'); 7 | 8 | prog.version('0.0.10') 9 | .usage('[options]') 10 | .option('-e, --edition ', 'Choose an edition of the brief (integer)', parseInt) 11 | .parse(process.argv); 12 | 13 | var edition = prog.edition || 0; 14 | var displayColors = ['cyan', 'yellow', 'red', 'white', 'grey']; 15 | 16 | // extremely non-robust way to strip links from content 17 | var hrefRe = //g; 18 | var linkCounter = 1; 19 | var links = []; 20 | 21 | function stripLinks (content) { 22 | var $ = cheerio.load(content); 23 | $('a').each(function (d, i) { 24 | var href = $(this).attr('href'); 25 | var counterStr = '[' + linkCounter + ']'; 26 | links.push(counterStr + ' ' + href.underline); 27 | linkCounter++; 28 | }); 29 | 30 | content = content.replace(hrefRe, '') 31 | .replace(/<\/a>/, '') 32 | .replace(//, '*') 33 | .replace(/<\/i>/, '*') 34 | .replace('
', ''); 35 | 36 | return content; 37 | } 38 | 39 | function sectionStr (section) { 40 | var str = '\n\n'; 41 | str += section.sectionTitle.bold[displayColors[1]]; 42 | 43 | var items = section.sectionItems; 44 | items.forEach(function (item) { 45 | str += [ 46 | '\n\n', 47 | item.tout[displayColors[2]], 48 | ' ', 49 | stripLinks(item.content)[displayColors[3]], 50 | ].join(''); 51 | }); 52 | 53 | return str; 54 | } 55 | 56 | function parseRes (json) { 57 | var currSections = json.editions[edition].sections; 58 | 59 | var finalStr = [ 60 | '\n', 61 | cachedText.intro.bold[displayColors[0]], 62 | sectionStr(currSections.watch), 63 | sectionStr(currSections.sleep), 64 | sectionStr(currSections.debate), 65 | sectionStr(currSections.discoveries), 66 | '\n\n', 67 | 'Links from this brief:'[displayColors[0]], 68 | '\n\n', 69 | links.join('\n'), 70 | '\n\n', 71 | cachedText.outro[displayColors[3]], 72 | '\n\n', 73 | cachedText.footer[displayColors[4]] 74 | ].join(''); 75 | 76 | console.log(wrap(finalStr)); 77 | } 78 | 79 | module.exports = parseRes; 80 | --------------------------------------------------------------------------------