From bfeb48d159980c69193978242c8e2fbe7815811b Mon Sep 17 00:00:00 2001 From: yehor Date: Thu, 6 Feb 2025 14:49:13 +0200 Subject: [PATCH] Add ability to skip number of records --- bin/owntracks_import.dart | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/bin/owntracks_import.dart b/bin/owntracks_import.dart index 9a93f86..92749ad 100644 --- a/bin/owntracks_import.dart +++ b/bin/owntracks_import.dart @@ -13,6 +13,9 @@ ArgParser buildParser() { ..addOption('destination', abbr: 'd', help: 'OwnTracks Recorder server address') ..addOption('user', abbr: 'u', help: 'User for OwnTrack record') + ..addOption('continue', + abbr: 'c', + help: 'The number of record to continue import from (Starting from 1)') ..addFlag( 'help', abbr: 'h', @@ -81,9 +84,34 @@ void main(List arguments) async { final List failedList = []; + final rawContinueFrom = results.option('continue'); + + final continueFrom = + rawContinueFrom == null ? 1 : int.parse(rawContinueFrom); + int n = 1; + if (continueFrom > recordsList.length) { + throw FormatException('There are only ${recordsList.length} in the list'); + } + for (final record in recordsList) { + if (n < continueFrom) { + if (verbose) { + print(' '); + print('Record $n of ${recordsList.length} SKIPPED'); + } + + n++; + + continue; + } + + if (verbose) { + print(' '); + print('Record $n of ${recordsList.length}'); + } + final Map payload = {'_type': 'location', 't': 'u'}; final recordProps = record['properties']; @@ -121,8 +149,6 @@ void main(List arguments) async { payload['conn'] = recordProps['connection']; if (verbose) { - print(' '); - print('Record $n of ${recordsList.length}'); print(payload); } @@ -137,7 +163,6 @@ void main(List arguments) async { final url = '${results.option('destination')}/pub?u=$user&d=$device'; if (verbose) { - print(' '); print('...Sending to: $url'); }