Skip to content

Instantly share code, notes, and snippets.

@pospi
Created June 8, 2025 08:58
Show Gist options
  • Save pospi/0df6db3d2769e248388232a32a690460 to your computer and use it in GitHub Desktop.
Save pospi/0df6db3d2769e248388232a32a690460 to your computer and use it in GitHub Desktop.
Convert Pocket export CSV to chunked Omnivore backup JSON files
/**
* Convert CSV from Pocket export file to chunked JSON files in
* Omnivore format.
* For import into Wallabag with minimal data loss.
*/
const { readFileSync, writeFileSync } = require('fs')
const { parse } = require('csv/sync')
const { format } = require('fecha')
const INPUT_FILENAME = './part_000000.csv'
const OUTPUT_FILE_PREFIX = './pocket2omnivore'
const CHUNK_LEN = 100
const data = parse(readFileSync(INPUT_FILENAME)).slice(1)
const formatted = data.map(row => ({
title: row[0],
url: row[1],
savedAt: format(new Date(parseInt(row[2], 10) * 1000), 'YYYY-MM-DDTHH:mm:ss.SSS000') + 'Z',
labels: row[3].split('|'),
state: row[4] === 'archive' ? 'Archived' : 'Unread',
author: null,
publishedAt: null,
}))
for (let i = 0, l = Math.ceil(formatted.length / CHUNK_LEN); i < l; ++i) {
writeFileSync(
`${OUTPUT_FILE_PREFIX}-${i}.json`,
JSON.stringify(formatted.slice(i * CHUNK_LEN, i * CHUNK_LEN + CHUNK_LEN), null, 2),
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment