Created
January 15, 2019 01:09
-
-
Save nikezono/7dc7517b4cd36d86dd86647cb77d582d to your computer and use it in GitHub Desktop.
convert atom exported by hatena-bookmark to json which can import to scrapbox
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 fs = require('fs'); | |
| const FeedParser = require('feedparser'); | |
| const FILEPATH = process.argv[2]; | |
| if (!FILEPATH) { | |
| console.error('Invalid argument: must be node feed2scrapbox.js [FILEPATH]'); | |
| process.exit(1); | |
| } | |
| let pages = []; | |
| const stream = fs.createReadStream(FILEPATH); | |
| stream.on('error', (e) => { | |
| console.error(e); | |
| process.exit(1); | |
| }); | |
| const feedparser = new FeedParser(); | |
| stream.pipe(feedparser); | |
| feedparser.on('error', (e) => { | |
| console.error(e); | |
| process.exit(1); | |
| }); | |
| feedparser.on('readable', (e) => { | |
| let item; | |
| while (item = feedparser.read()) { | |
| const title = 100 < item.title.length ? item.title.slice(0, 96) + "..." : item.title | |
| pages.push({ | |
| 'title': title, | |
| 'lines': | |
| [item.title.trim(), '', item['atom:link'][0]['@'].href] | |
| }); | |
| } | |
| }); | |
| feedparser.on('end', () => { | |
| console.log(JSON.stringify({'pages': pages}, null, 2)); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment