File: collecttypes.py

package info (click to toggle)
python-libais 0.17%2Bgit.20190917.master.e464cf8-5
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 5,820 kB
  • sloc: cpp: 56,058; python: 11,979; makefile: 537; sh: 466
file content (32 lines) | stat: -rwxr-xr-x 725 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#! /usr/bin/env python

import ais
import sys
import ais.compatibility.gpsd
import ais.stream

args = {}
files = []
for arg in sys.argv[1:]:
    if arg.startswith("--"):
        arg = arg[2:]
        if '=' in arg:
            arg, value = arg.split("=", 1)
            args[arg] = value
        else:
            args[arg] = True
    else:
        files.append(arg)

if "help" in args:
    print """Usage: collecttypes.py < INFILE.nmea > OUTFILE.nmea

Collects one message of each type.
"""
    sys.exit(0)

types = set()
for msg in ais.stream.decode(sys.stdin, keep_nmea=True, allowUnknown=True, allow_missing_timestamps=True):
    if msg['id'] in types: continue
    types.add(msg['id'])
    sys.stdout.write(msg['nmea'])