add export of firefox places

This commit is contained in:
Tykayn 2023-03-15 22:00:07 +01:00 committed by tykayn
parent 229d71b4a1
commit dd7acaa446
3 changed files with 87 additions and 12 deletions

View File

@ -0,0 +1,74 @@
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);

View File

@ -11,18 +11,7 @@ const fileArray = ["2007-07-01 De juillet 2007 à septembre 2007.json","2007-10-
const fileNameAllEvents = 'all_researches.tsv';
const headersTsv = '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'
let allEvents = [
headersTsv
];

12
utils.mjs Normal file
View File

@ -0,0 +1,12 @@
export const headersTsv = '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'