Last active
March 6, 2018 17:32
-
-
Save styts/01055fd5fb1b36a52547e30cab31a28d to your computer and use it in GitHub Desktop.
Sample Tropy plugin
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
'use strict' | |
class Plugin { | |
constructor(config, context) { | |
this.config = config | |
this.context = context | |
} | |
async export(data) { | |
const { logger } = this.context | |
logger.info('Exporting items to CSV...') | |
const writeStream = require('fs').createWriteStream(this.config.output) | |
for (let items of data) { | |
for (let item of items['@graph']) { | |
try { | |
writeStream.write(`"${item.title}","${item.photo[0].path}"\n`) | |
} catch (e) { | |
logger.error(e.message) | |
} | |
} | |
} | |
writeStream.end() | |
} | |
} | |
module.exports = Plugin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment