1234567891011121314151617181920212223242526272829303132333435 |
- #!/usr/bin/env node
- import helper from './helper.js'
- import readline from 'readline'
- const rl = readline.createInterface({ input: process.stdin })
- rl.on('line', async line => {
- // 任务信息
- const job = JSON.parse(line)
- console.log("running job: " + job.id + ": " + JSON.stringify(job))
- // 检查参数
- const {
- notion_key: NOTION_KEY,
- database_id: DATABASE_ID,
- base_currency: BASE_CURRENCY
- } = job.params
- if (NOTION_KEY === null || DATABASE_ID === null || BASE_CURRENCY == null) {
- helper.returnFailed(1, 'params `notion_key`, `database_id`, ' +
- '`base_currency` required')
- return
- }
- // 获取源数据
- const rateMap = await helper.fetchExchangeRateData(BASE_CURRENCY)
- // 更新汇率
- await helper.updateRate(NOTION_KEY, DATABASE_ID, rateMap)
- // 处理成功
- helper.returnSuccess()
- rl.close();
- });
|