75 lines
2.4 KiB
JavaScript
75 lines
2.4 KiB
JavaScript
import fs from "node-fs";
|
|
import {writeFileInOuputFolder} from "./parse_orgmode_to_json.mjs";
|
|
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)
|
|
writeFileInOuputFolder(outputFileName, events.join("\n")).then(r => console.log('r', r))
|
|
})
|
|
}
|
|
|
|
convertJsonToActivities(sourceFilePath, outputFileName);
|
|
|
|
|
|
|
|
|