Created
July 19, 2018 23:40
-
-
Save julianfbeck/1382cc0f360598b8859b66dd38a255e6 to your computer and use it in GitHub Desktop.
Convert google sheet html exports to netscape bookmarks. One folder per sheet
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 characters
| const htmlparser = require("htmlparser"); | |
| const fs = require("fs") | |
| const cheerio = require('cheerio') | |
| const netscape = require('netscape-bookmarks'); | |
| const path = require("path"); | |
| let template = { | |
| Mia: { | |
| contents: {} | |
| }, | |
| } | |
| let files = fs.readdirSync("MIA Resources"); | |
| files.forEach(file => { | |
| if (path.extname(file) === ".html") { | |
| let folderName = path.basename(file).replace('.html', ''); | |
| template.Mia.contents[folderName] = {}; | |
| template.Mia.contents[folderName].contents = {}; | |
| let data = fs.readFileSync(path.join("MIA Resources", file), "utf8"); | |
| const $ = cheerio.load(data) | |
| let seletor = $("a[target=_blank]") | |
| let bookmark = {} | |
| for (let i = 0; i < seletor.length; i++) { | |
| let name = seletor[i].children[0].data; | |
| let link = seletor[i].children[0].parent.attribs.href; | |
| bookmark[name] = link; | |
| } | |
| template.Mia.contents[folderName].contents = bookmark; | |
| } | |
| }); | |
| let nets = netscape(template); | |
| fs.writeFile("Mia.html", nets, function (err) { | |
| if (err) { | |
| return console.log(err); | |
| } | |
| console.log("The file was saved!"); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment