Skip to content

Instantly share code, notes, and snippets.

@styts
Last active March 6, 2018 17:32
Show Gist options
  • Save styts/01055fd5fb1b36a52547e30cab31a28d to your computer and use it in GitHub Desktop.
Save styts/01055fd5fb1b36a52547e30cab31a28d to your computer and use it in GitHub Desktop.
Sample Tropy plugin
'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