diff --git a/kartaview_exif_mapper/3596249_trace.gpx b/kartaview_exif_mapper/3596249_trace.gpx new file mode 100644 index 00000000..d37e33f2 --- /dev/null +++ b/kartaview_exif_mapper/3596249_trace.gpx @@ -0,0 +1,50 @@ + + + + trace_gpx_de_demo + + somebody + + + 2023 + https://creativecommons.org/licenses/by-sa/2.5 + + nada + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/kartaview_exif_mapper/main.ts b/kartaview_exif_mapper/main.ts index 1d529dc9..7f24070c 100644 --- a/kartaview_exif_mapper/main.ts +++ b/kartaview_exif_mapper/main.ts @@ -3,48 +3,56 @@ conversion de données exif **/ import * as fs from 'node:fs'; +// @ts-ignore +import path from "node:path"; +import minimist from 'minimist'; -const dossier_photo: string = "/home/poule/encrypted/stockage-syncable/photos/imagerie kartaview carto tel/kartaview_export_storage/share2tykayn/photo/2785606" -const file_gpx: string = "/home/poule/encrypted/stockage-syncable/photos/imagerie kartaview carto tel/kartaview_export_storage/share2tykayn/metadata_file/3596249/3596249_d875a_60a0f9bf38f99.txt" +// configs +let sequence_name: string = '3596977' +const dossier_photo: string = "/home/poule/encrypted/stockage-syncable/photos/imagerie kartaview carto tel/kartaview_export_storage/share2tykayn/photo/" + sequence_name +let dossier_gpx: string = "." +const file_gpx: string = "/home/poule/encrypted/stockage-syncable/photos/imagerie kartaview carto tel/kartaview_export_storage/share2tykayn/metadata_file/" + sequence_name + "/3596249_d875a_60a0f9bf38f99.txt" let gpxData: any = {} -let tableKartaviewTrace = [] +let tableKartaviewTrace: any = [] +let mini_arguments :any = minimist(process.argv.slice(2)) +console.log('mini_arguments', mini_arguments) + +if(mini_arguments['sequence']){ + sequence_name = mini_arguments['sequence'] +} function makeGpxFromKartaview() { - let track_points; + let track_points: string = ''; // TODO build track points tableKartaviewTrace.forEach((elem: any) => { - track_points = track_points + '\n' + track_points = `${track_points} + +` }) - let content = '\n' + - '\n' + - ' \n' + - ' trace_gpx_de_demo\n' + - ' \n' + - ' somebody\n' + - ' \n' + - ' \n' + - // ' 2022\n' + - ' https://creativecommons.org/licenses/by-sa/2.5\n' + - ' \n' + - ' nada\n' + - // ' \n' + - // ' \n' + - ' \n' + - // ' \n' + - // ' \n' + - ' \n' + - ' \n' + - track_points + - // ' \n' + - ' \n' + - ' \n' + - ' \n' + - '' + let content = ` + + + trace_gpx_de_demo + + somebody + + + 2023 + https://creativecommons.org/licenses/by-sa/2.5 + + nada + + + + ${track_points} + + +` return content; } @@ -59,14 +67,15 @@ function openGPX(filepath: any) { const gpx_content = data; let lines = gpx_content.split('\n') console.log('lines.length', lines.length) + + // loop on all lines, only take the lines that contain :g: lines.forEach((elem: any) => { if (elem.indexOf(":g:") > -1) { + // do stuff on gpxData to enrich it let boom = elem.split(':') let gpsmodel = boom[2] let gps = gpsmodel.split(';') tableKartaviewTrace.push(gps) - // console.log('boom', boom) - // console.log('gps', gps) let date = new Date(boom[0] * 1000) console.log('*', date, gps[0], gps[1]) @@ -74,21 +83,42 @@ function openGPX(filepath: any) { }) let content_gpx = makeGpxFromKartaview() - // writeFile('./output.gpx', content_gpx) + writeFile('' + sequence_name + '_trace.gpx', content_gpx) // console.log('gpx_content', gpx_content) }) - // loop on all lines, only take the lines that contain :g: - // do stuff on gpxData to enrich it } -function writeFile(name, content) { - console.log('name,content', name, content) - fs.writeFileSync(name,content) -} -function getAllFilesInFolder(folderPath: any) { - let listOfFiles: any = [] - return listOfFiles +let cwd = path.dirname(process.cwd()) + '/' + path.basename(process.cwd()) + +let expandedFileList: any = [] + +/** + * get a list of all files in a path + * @param folderPath + */ +function getAllFilesInFolder(folderPath: string) { + let filesList: any = [] + + fs.readdir(folderPath, (err, filesList) => { + if (err) throw err + + console.log('readSubdirectories - files', filesList) + + filesList.forEach((subDirOrFile) => { + const newFullPath = cwd + '/' + subDirOrFile + + if (fs.existsSync(newFullPath)) { + const s = fs.statSync(newFullPath) + + if (s.isFile()) { + expandedFileList.push(cwd + '/' + subDirOrFile) + } + } + }) + + return filesList; + }) } function mapExifDataOnListOfFilesFromGpxData(listOfFiles: any, gpxData: any) { @@ -99,6 +129,22 @@ function mapExifDataOnListOfFilesFromGpxData(listOfFiles: any, gpxData: any) { }) } +function writeFile(fileName: string, fileContent: any) { + console.log('write file', fileName) + return fs.writeFile( + `${dossier_gpx}/${fileName}`, + fileContent, + 'utf8', + (err) => { + if (err) { + console.log(`Error writing file: ${err}`) + } + } + ) +} + + openGPX(file_gpx) let listOfFiles: any = getAllFilesInFolder(dossier_photo) + console.log('listOfFiles', listOfFiles)