up convert sms
This commit is contained in:
parent
a491c12d15
commit
bbcb33e531
|
@ -1,16 +1,17 @@
|
|||
import fs from "node-fs";
|
||||
import convert from "xml-js";
|
||||
import {writeFileInOuputFolderFromJsonObject} from "./parse_orgmode_to_json.mjs";
|
||||
import {writeFileInOuputFolderFromJsonObject} from "./utils.mjs";
|
||||
|
||||
/**********************
|
||||
* initialize configs
|
||||
**********************/
|
||||
|
||||
const sourceFileName = 'sms-20180423162531.xml'
|
||||
const sourceFileName = 'sms.xml'
|
||||
const outputFileJson = 'sms-20180423162531.json'
|
||||
const sourceFileJson = 'output/' + outputFileJson
|
||||
const outputFileCsv = 'sms-20180423162531.tsv'
|
||||
const sourceFilePath = '/home/tykayn/Nextcloud/ressources/social sorting/' + sourceFileName;
|
||||
const outputFileJsonPathFull = '/home/cipherbliss/Nextcloud/ressources/social sorting/output/' + outputFileJson
|
||||
const sourceFileJson = '/home/cipherbliss/Nextcloud/ressources/social sorting/output/' + outputFileJson
|
||||
const sourceFilePath = '/home/cipherbliss/Nextcloud/ressources/social sorting/' + sourceFileName;
|
||||
|
||||
let headers = []
|
||||
let tasksObjectsForJsonExport = []
|
||||
|
@ -38,6 +39,9 @@ function convertToCsv(elementsArray) {
|
|||
function convertJsonToCsv(sourceFilePath, outputFileName) {
|
||||
fs.readFile(sourceFilePath, 'utf8', function (err, data) {
|
||||
|
||||
console.log('data', data)
|
||||
if (data) {
|
||||
|
||||
const events = [
|
||||
|
||||
'amount\t' +
|
||||
|
@ -76,6 +80,10 @@ function convertJsonToCsv(sourceFilePath, outputFileName) {
|
|||
})
|
||||
console.log('events', events)
|
||||
writeFileInOuputFolderFromJsonObject(outputFileName, events.join("\n"))
|
||||
|
||||
} else {
|
||||
console.error('no data in xml file ' + sourceFilePath)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -94,7 +102,7 @@ function openSourceFile() {
|
|||
// console.log('smses', Object.keys(jsonConversion))
|
||||
console.log('jsonConversion[0]', jsonConversion['10'])
|
||||
|
||||
writeFileInOuputFolderFromJsonObject(outputFileJson, jsonConversion)
|
||||
writeFileInOuputFolderFromJsonObject(outputFileJsonPathFull, jsonConversion)
|
||||
convertJsonToCsv(sourceFileJson, outputFileCsv)
|
||||
|
||||
})
|
||||
|
@ -111,49 +119,4 @@ function openSourceFile() {
|
|||
}
|
||||
|
||||
|
||||
// openSourceFile()
|
||||
|
||||
function convertJsonToCsv(sourceFilePath, outputFileName) {
|
||||
fs.readFile(sourceFilePath, 'utf8', function (err, data) {
|
||||
|
||||
const events = [
|
||||
|
||||
'amount\t' +
|
||||
'content\t' +
|
||||
'description\t' +
|
||||
'destination\t' +
|
||||
'end\t' +
|
||||
'kind of activity\t' +
|
||||
'person\t' +
|
||||
'place\t' +
|
||||
'source\t' +
|
||||
'start\t' +
|
||||
'unique id\t' +
|
||||
'url\t'
|
||||
];
|
||||
data = JSON.parse(data)
|
||||
console.log('data', data)
|
||||
// console.log('data', Object.keys(data[0]))
|
||||
data['smses']['sms'].forEach(item => {
|
||||
|
||||
// convert all fields to common event description
|
||||
events.push(
|
||||
'\t' +
|
||||
item._attributes.body.replace('\n', ' ') + '\t' +
|
||||
'sms ' + item._attributes.address + ' le '+item._attributes.readable_date+'\t' +
|
||||
item._attributes.address + '\t' +
|
||||
'' + '\t' +
|
||||
'' + '\t' +
|
||||
item._attributes.contact_name + '\t' +
|
||||
'' + '\t' +
|
||||
'' + '\t' +
|
||||
'' + '\t' +
|
||||
'' + '\t' +
|
||||
'' + '\t'
|
||||
)
|
||||
})
|
||||
console.log('events', events)
|
||||
writeFileInOuputFolderFromJsonObject(outputFileName, events.join("\n"))
|
||||
})
|
||||
}
|
||||
|
||||
openSourceFile()
|
||||
|
|
|
@ -20,8 +20,8 @@ export async function writeFileInOuputFolderFromJsonObject(fileName, jsonObjectT
|
|||
// console.log('statistics.dates', statistics.dates)
|
||||
|
||||
return await fs.writeFile(
|
||||
`${fileName}`,
|
||||
JSON.stringify(jsonObjectThing),
|
||||
`${outputAbsolutePath}${fileName}`,
|
||||
JSON.stringify(jsonObjectThing, null, 2),
|
||||
"utf8",
|
||||
(err) => {
|
||||
if (err) {
|
||||
|
|
Loading…
Reference in New Issue