-
-
Save bansicloud/cc976411da744b54177796e4c345c263 to your computer and use it in GitHub Desktop.
Revisions
-
reichert621 revised this gist
Jun 1, 2020 . No changes.There are no files selected for viewing
-
reichert621 revised this gist
May 30, 2020 . 1 changed file with 32 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ const moment = require('moment'); const request = require('superagent'); const cheerio = require('cheerio'); const _ = require('lodash'); const scraper = async () => { const url = 'https://news.ycombinator.com/jobs' const {text: html} = await request.get(url); const $ = cheerio.load(html); const links = $('.storylink').map((i, el) => { return {href: $(el).attr('href'), text: $(el).text()}; }); const ages = $('.age').map((i, el) => $(el).text()); const formatted = _.zip(links, ages).map(([link, age]) => { return { text: link.text, link: link.href, age: age, }; }); const recent = formatted.filter((item) => { // item.age looks like "16 hours ago", "2 days ago", etc. const [num, time] = item.age.split(' '); const threshold = moment().subtract(24, 'hours'); return moment().subtract(num, time) > threshold; }); return recent; }; scraper().then(console.log).catch(console.log); -
reichert621 revised this gist
May 30, 2020 . 4 changed files with 57 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ const request = require('superagent'); const checkItemInStock = async () => { const {text: html} = await request.get( 'https://www.bowflex.com/selecttech/552/100131.html' ); const inStock = html.toLowerCase().indexOf('out of stock') === -1; return {inStock}; }; checkItemInStock().then(console.log).catch(console.log); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ const request = require('superagent'); const cheerio = require('cheerio'); const _ = require('lodash'); const scraper = async (threshold = 200) => { const url = 'https://news.ycombinator.com/' const {text: html} = await request.get(url); const $ = cheerio.load(html); const links = $('.storylink').map((i, el) => { return {href: $(el).attr('href'), text: $(el).text()}; }); const scores = $('.score').map((i, el) => $(el).text()); const formatted = _.zip(links, scores).map(([link, score]) => { return { text: link.text, link: link.href, score: score && Number(score.replace(/\D/g, '')), }; }); const top = formatted.filter((item) => item.score > threshold); return top; }; scraper().then(console.log).catch(console.log); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ const request = require('superagent'); const _ = require('lodash'); const getRandomInspirationalQuote = async () => { const {text: json} = await request.get('https://type.fit/api/quotes'); const quotes = JSON.parse(json); return _.sample(quotes); }; getRandomInspirationalQuote().then(console.log).catch(console.log); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ const request = require('superagent'); const ping = async () => { const res = await request.get('https://taro-beta.herokuapp.com/api/ping'); return res.body; }; ping().then(console.log).catch(console.log); -
reichert621 created this gist
May 30, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ const request = require('superagent'); const _ = require('lodash'); const getTopPosts = async (subreddit, options = {}) => { const {count = 10, interval = 'week'} = options; const sub = `https://www.reddit.com/r/${subreddit}/top.json?sort=top&t=${interval}`; const res = await request.get(sub); const {children: posts} = res.body.data; return posts.slice(0, count).map((post) => { const {title, subreddit, score, url} = post.data; return {title, subreddit, score, url}; }); }; const getTopPostsInFavoriteSubreddits = async ( subreddits, options = {} ) => { const {count = 5, interval = 'week'} = options; const promises = subreddits.map((sub) => { return getTopPosts(sub, {count, interval}); }); return Promise.all(promises).then(_.flatten); }; getTopPostsInFavoriteSubreddits([ 'programming', 'javascript', 'learnprogramming', ]) .then(console.log) .catch(console.log);