From f34e7a3a6103448f477f03af1bd6bac5bcadf1f5 Mon Sep 17 00:00:00 2001 From: Egil Date: Mon, 27 Aug 2018 13:35:53 +0200 Subject: [PATCH] Synthesize missing timedstamps from now --- ais/stream/__init__.py | 5 +++++ bin/aisdecode | 1 + 2 files changed, 6 insertions(+) diff --git a/ais/stream/__init__.py b/ais/stream/__init__.py index 8a1271f2..f927eda0 100644 --- a/ais/stream/__init__.py +++ b/ais/stream/__init__.py @@ -6,6 +6,7 @@ import ais from ais.stream import checksum +import time warnings.warn( "The stream module is deprecated and will be removed in 1.0", @@ -154,6 +155,7 @@ def normalize(nmea=sys.stdin, treat_ab_equal=False, pass_invalid_checksums=False, allow_missing_timestamps=False, + missing_timestamp_to_now=False, errorcb=ErrorPrinter, stats=None, **kw): @@ -324,6 +326,7 @@ def decode(nmea=sys.stdin, errorcb=ErrorPrinter, keep_nmea=False, stats=None, + missing_timestamp_to_now=False, **kw): """Decodes a stream of AIS messages. Takes the same arguments as normalize.""" @@ -341,6 +344,8 @@ def report_error(e): res.update(tagblock) if keep_nmea: res['nmea'] = origline + if missing_timestamp_to_now and 'tagblock_timestamp' not in res: + res['tagblock_timestamp'] = time.time() yield res except TooManyErrorsError: raise diff --git a/bin/aisdecode b/bin/aisdecode index d36a19f8..341ad570 100755 --- a/bin/aisdecode +++ b/bin/aisdecode @@ -67,6 +67,7 @@ Available opptions: --treat_ab_equal --pass_invalid_checksums --allow_missing_timestamps + --missing_timestamp_to_now --uscg=False --validate_checksum=False