Created
August 15, 2017 03:53
-
-
Save tusharmath/ef979bc45d04a0911c26dcc493df0e70 to your computer and use it in GitHub Desktop.
Scrapes all the download urls of color sublime themes
This file contains 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 characters
const R = require('ramda') | |
const O = require('observable-air') | |
const axios = require('axios') | |
const { JSDOM } = require('jsdom') | |
const makeRequest = url => | |
axios.get(url).then(response => response.data).then(html => new JSDOM(html)) | |
const fetchDOM = url => O.multicast(O.fromPromise(() => makeRequest(url))) | |
const fromArray = R.compose(O.fromArray, Array.from) | |
const findE = R.curry((sel, dom) => | |
fromArray(dom.window.document.querySelectorAll(sel)) | |
) | |
const findDownloadURLS = R.compose( | |
O.map(R.prop('href')), | |
O.join, | |
O.map(findE('.download')) | |
) | |
const findPages = R.compose( | |
O.filter(R.test(/http/)), | |
O.map(R.prop('href')), | |
O.join, | |
O.map(findE('.pagination a')) | |
) | |
const unique = (def, fn) => { | |
const set = new Set() | |
return p => { | |
if (set.has(p)) return def() | |
set.add(p) | |
return fn(p) | |
} | |
} | |
const main = unique(O.empty, url => { | |
const dom$ = fetchDOM(url) | |
const paginationURL$ = findPages(dom$) | |
const downloadURL$ = findDownloadURLS(dom$) | |
return O.merge(downloadURL$, O.flatMap(main, paginationURL$)) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment