├── README.md ├── .gitignore ├── package.json ├── LICENSE └── index.js /README.md: -------------------------------------------------------------------------------- 1 | # subreddit-stylesheet-downloader 2 | Downloads stylesheets from the most popular subreddits (for analysis). 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directories 30 | node_modules 31 | jspm_packages 32 | 33 | # Optional npm cache directory 34 | .npm 35 | 36 | # Optional REPL history 37 | .node_repl_history 38 | 39 | # IntelliJ 40 | *.iml 41 | .idea 42 | 43 | # Output dir 44 | css 45 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "subreddit-stylesheet-downloader", 3 | "version": "0.0.0", 4 | "description": "Downloads stylesheets from the most popular subreddits (for analysis).", 5 | "private": true, 6 | "main": "index.js", 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/erikdesjardins/subreddit-stylesheet-downloader.git" 10 | }, 11 | "author": "Erik Desjardins", 12 | "license": "MIT", 13 | "bugs": { 14 | "url": "https://github.com/erikdesjardins/subreddit-stylesheet-downloader/issues" 15 | }, 16 | "homepage": "https://github.com/erikdesjardins/subreddit-stylesheet-downloader#readme", 17 | "scripts": { 18 | "start": "cross-env REDDIT_USER_AGENT=user_agent REDDIT_KEY=key REDDIT_SECRET=secret REDDIT_USER=user REDDIT_PASS=pass node ." 19 | }, 20 | "dependencies": { 21 | "escape-string-regexp": "^1.0.5", 22 | "mkdirp": "^0.5.1", 23 | "mz": "^2.4.0", 24 | "snoocore": "^3.3.1" 25 | }, 26 | "devDependencies": { 27 | "cross-env": "^2.0.0" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Erik Desjardins 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 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const mkdirp = require('mkdirp'); 3 | const fs = require('mz/fs'); 4 | const Snoocore = require('snoocore'); 5 | const escapeStringRegexp = require('escape-string-regexp'); 6 | 7 | const outDir = path.join(__dirname, 'css'); 8 | 9 | const r = new Snoocore({ 10 | userAgent: process.env.REDDIT_USER_AGENT, 11 | oauth: { 12 | type: 'script', 13 | key: process.env.REDDIT_KEY, 14 | secret: process.env.REDDIT_SECRET, 15 | username: process.env.REDDIT_USER, 16 | password: process.env.REDDIT_PASS, 17 | }, 18 | throttle: 0, 19 | decodeHtmlEntities: true, 20 | }); 21 | 22 | r('/subreddits/popular').get({ limit: 100 }).then(({ data: { children: subreddits } }) => { 23 | const count = subreddits.length; 24 | let complete = 0; 25 | 26 | mkdirp.sync(outDir); 27 | 28 | for (const subreddit of subreddits.map(s => s.data.display_name)) { 29 | r('/r/$subreddit/about/stylesheet').get({ $subreddit: subreddit }).then(({ data: { stylesheet, images } }) => { 30 | stylesheet = images.reduce( 31 | (s, { link, url }) => s.replace(new RegExp(escapeStringRegexp(link), 'gi'), `url(${url})`), 32 | stylesheet 33 | ); 34 | 35 | fs.writeFile(path.join(outDir, `${subreddit}.css`), stylesheet).then( 36 | () => { console.log(`[${++complete}/${count}] ${subreddit} complete.`); }, 37 | e => { 38 | console.error(e); 39 | process.exitCode = 1; 40 | } 41 | ); 42 | }); 43 | } 44 | }); 45 | --------------------------------------------------------------------------------