master
Clement Bois 2019-06-14 17:30:54 +02:00
parent f07baecee4
commit c5e243337e
2 changed files with 24 additions and 12 deletions

View File

@ -2,7 +2,7 @@ import { rest, rootStatus } from '../../prepare'
import Logger from '../../utils/Logger'
async function run() {
const content = process.argv[2]
const [,,content, visibility] = process.argv
if (!content) {
Logger.error('require content')
return
@ -11,7 +11,7 @@ async function run() {
const status = await rest.postStatus({
in_reply_to_id: rootStatus,
status: content,
visibility: 'private'
visibility: visibility as any || 'direct'
})
Logger.info('action added', { id: status.id, tags: status.tags.map(t => t.name).reverse() })
}

View File

@ -3,20 +3,32 @@ import { rest, rootStatus } from '../../prepare'
import Logger from '../../utils/Logger'
async function run() {
const [,, file, title] = process.argv
const [,, file, title, visibility] = process.argv
if (!file) {
Logger.error('require file')
return
}
const post = async (in_reply_to_id: string, status: string) => rest.postStatus({
in_reply_to_id, status,
visibility: visibility as any || 'direct'
}).then(s => s.id)
const data = JSON.parse(fs.readFileSync(file, 'utf8'))
const ok = data.map((l: any) => Object.entries(l).map(([lang, message]) => `[${lang}] ${message}`).join('\n'))
Logger.info('data', ok)
/*
const status = await rest.postStatus({
in_reply_to_id: rootStatus,
status: content,
visibility: 'private'
})
Logger.info('action added', { id: status.id, tags: status.tags.map(t => t.name).reverse() })*/
const folder = await post(rootStatus, title || file)
for (const row of data) {
if (typeof row === 'string') {
await post(folder, row)
} else if (typeof row === 'object') {
const content = '\n' + Object.entries(row).map(([lang, message]) => `[${lang}] ${message}`).join('\n\n')
const global = await post(folder, content)
for (const [lang, message] of Object.entries(row)) {
await post(global, `${message} #${lang}`)
}
} else {
throw new Error('bad type ' + typeof row)
}
}
Logger.info('data added', folder)
}
run()