Skip to content

Instantly share code, notes, and snippets.

@simov
Created September 8, 2019 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simov/8bffb278db0c0ba99b6fab0ca4d5fc96 to your computer and use it in GitHub Desktop.
Save simov/8bffb278db0c0ba99b6fab0ca4d5fc96 to your computer and use it in GitHub Desktop.
Dev.to Dashboard
var compose = require('request-compose')
// DevTools -> Application -> Cookies
var token = '...'
var parse = (regex, string, map = (a) => a, result = [], match = regex.exec(string)) =>
!match ? result : parse(regex, string, map, result.concat(map(match)))
var regex = new RegExp([
/single-article/.source,
/a.*?href="(.*?)"/.source,
/h2>(.*?)</.source,
/Published.+datetime="(.*?)"/.source,
/data-article-id="(\d+)"/.source,
/(\d+)[\s\S]+?views/.source,
/(\d+)[\s\S]+?reactions/.source,
/(\d+)[\s\S]+?comments/.source,
].join('[\\s\\S]+?'), 'gi')
var article = ([match, path, title, published, id, views, reactions, comments]) => ({
id: parseInt(id),
title: title.trim(),
url: `https://dev.to${path}`,
published,
tags: parse(/href="\/t\/(.*?)"/gi, match, (a) => a.slice(1)),
views: parseInt(views),
reactions: parseInt(reactions),
comments: parseInt(comments),
})
var dashboard = compose(
({token}) => compose.client({
url: 'https://dev.to/dashboard',
headers: {
cookie: `remember_user_token=${token};`,
},
}),
({body}) => parse(regex, body, article),
)
;(async () => {
try {
console.log(await dashboard({token}))
}
catch (err) {
console.log(err)
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment