2023-03-15 22:00:07 +01:00
|
|
|
import fs from "node-fs";
|
2023-04-18 12:23:52 +02:00
|
|
|
import {writeFileInOuputFolderFromJsonObject} from "./parse_orgmode_to_json.mjs";
|
2023-03-15 22:00:07 +01:00
|
|
|
import moment from "moment";
|
|
|
|
import {headersTsv} from "./utils.mjs";
|
|
|
|
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* initialize configs
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
const sourceFilePath = "/home/tykayn/Nextcloud/ressources/social sorting/2023-01-03_firefox_places.json"
|
|
|
|
const outputFileName = '2023-01-03_firefox_places.tsv';
|
|
|
|
|
|
|
|
const events = [headersTsv];
|
|
|
|
let counter = 0;
|
|
|
|
let max_count = 10000
|
|
|
|
|
|
|
|
function convertJsonToActivities(sourceFilePath, outputFileName) {
|
|
|
|
fs.readFile(sourceFilePath, 'utf8', function (err, data) {
|
|
|
|
|
|
|
|
|
|
|
|
data = JSON.parse(data)
|
|
|
|
// console.log('data', Object.keys(data[0]))
|
|
|
|
data.forEach(item => {
|
|
|
|
|
|
|
|
if (counter < max_count) {
|
|
|
|
counter++;
|
|
|
|
// let timemoment = moment.unix(item.query.id[0].timestamp_usec)
|
|
|
|
// let stamp = Math.round(item.last_visit_date / 1000);
|
|
|
|
let stamp = item.last_visit_date
|
|
|
|
let mydate = null
|
|
|
|
if (item.last_visit_date) {
|
|
|
|
stamp = Math.round(item.last_visit_date / 1000)
|
|
|
|
// mydate = new Date(stamp)
|
|
|
|
mydate = moment(stamp).format()
|
|
|
|
}
|
|
|
|
|
|
|
|
let url = '';
|
|
|
|
|
|
|
|
if (item.url) {
|
|
|
|
url = item.url.replace('\n', ' ')
|
|
|
|
}
|
|
|
|
|
|
|
|
// return;
|
|
|
|
// console.log('mydate',item.query.id[0].timestamp_usec, item.query.id[0].timestamp_usec.length , stamp, mydate)
|
|
|
|
// convert all fields to common event description
|
|
|
|
let newLine =
|
|
|
|
item.visit_count + '\t' +
|
|
|
|
item.title + '\t' +
|
|
|
|
item.description + '\t' +
|
|
|
|
item.preview_image_url + '\t' +
|
|
|
|
'' + '\t' +
|
|
|
|
'firefox_place' + '\t' +
|
|
|
|
'' + '\t' +
|
|
|
|
'' + '\t' +
|
|
|
|
mydate + '\t' +
|
|
|
|
'' + '\t' +
|
|
|
|
'' + '\t'
|
|
|
|
url + '\t' +
|
|
|
|
''
|
|
|
|
// console.log('mydate',stamp, mydate)
|
|
|
|
events.push(newLine)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
console.log('events', events.length)
|
2023-04-18 12:23:52 +02:00
|
|
|
writeFileInOuputFolderFromJsonObject(outputFileName, events.join("\n")).then(r => console.log('r', r))
|
2023-03-15 22:00:07 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
convertJsonToActivities(sourceFilePath, outputFileName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|