├── package.json ├── README.md └── cutters.js /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cutters", 3 | "version": "1.1.1", 4 | "description": "Get Cutters salons sorted by wait time", 5 | "main": "cutters.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/draperunner/cutters.git" 9 | }, 10 | "scripts": { 11 | "start": "node cutters.js" 12 | }, 13 | "bin": { 14 | "cutters": "./cutters.js" 15 | }, 16 | "keywords": [], 17 | "author": "Mats Byrkjeland ", 18 | "license": "MIT", 19 | "dependencies": {} 20 | } 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cutters :haircut: 2 | 3 | Get Cutters hair salons sorted by wait time in the terminal. 4 | 5 | ``` 6 | $ npx cutters | grep Oslo | head -3 7 | Oslo City Oslo 2 min 2 waiting 8 | Stortingsgata Oslo 8 min 1 waiting 9 | Gunerius Oslo 12 min 0 waiting 10 | ``` 11 | 12 | Just run this: 13 | 14 | ``` 15 | npx cutters 16 | ``` 17 | 18 | Or install it first, if that's your style: 19 | 20 | ``` 21 | npm i -g cutters 22 | cutters 23 | ``` 24 | 25 | Manipulate the result with common bash commands: 26 | 27 | ``` 28 | npx cutters | grep Oslo | head -3 29 | ``` 30 | 31 | Need to follow how wait times are changing? 32 | 33 | ``` 34 | watch -n 10 'cutters | grep Oslo | head -10' 35 | ``` 36 | -------------------------------------------------------------------------------- /cutters.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const https = require('https') 3 | 4 | function get(url) { 5 | return new Promise((resolve, reject) => { 6 | const request = https.get(url, (response) => { 7 | if (response.statusCode >= 400) { 8 | return reject(new Error('Could not get salon info. Status code', response.statusCode)); 9 | } 10 | const body = []; 11 | response.on('data', (chunk) => body.push(chunk)); 12 | response.on('end', () => resolve(body.join(''))); 13 | request.on('error', (err) => reject(err)) 14 | }) 15 | }) 16 | } 17 | 18 | async function printTimes() { 19 | try { 20 | const res = await get('https://www.cutters.no/api/salons') 21 | const salonsData = JSON.parse(res).salons 22 | salonsData 23 | .sort((a, b) => a.details.estimatedWait - b.details.estimatedWait) 24 | .map(({ name, postalPlace, details }) => ({ 25 | estimatedWait: `${Math.round(details.estimatedWait / 60000)} min`, 26 | numberOfWaiting: details.numberOfWaiting, 27 | name, 28 | postalPlace, 29 | })) 30 | .forEach(({ name, postalPlace, estimatedWait, numberOfWaiting }) => { 31 | console.log(`${name.padEnd(30, ' ')}${postalPlace.padEnd(14, ' ')}${estimatedWait}\t${numberOfWaiting} waiting`) 32 | }) 33 | } catch (error) { 34 | console.error(error.message); 35 | } 36 | } 37 | 38 | printTimes() 39 | --------------------------------------------------------------------------------