From 0b0fbd76a7ed44a680cf6a383ee4563ef1ba4c43 Mon Sep 17 00:00:00 2001 From: D0han Date: Mon, 30 Sep 2019 01:18:10 +0200 Subject: [PATCH] Crude implementation of CHIRP csv bookmarks import --- tools/bookmark_integrator | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 tools/bookmark_integrator diff --git a/tools/bookmark_integrator b/tools/bookmark_integrator new file mode 100755 index 0000000..3c25b89 --- /dev/null +++ b/tools/bookmark_integrator @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +import json +import csv +import sys +from pprint import pprint + + +with open("../bookmarks.json") as f: + bookmarks = json.load(f) + +modulation_map = {"FM": "nfm", "NFM": "nfm"} + +in_file = sys.argv[1] +to_integrate = [] +with open(in_file) as f: + reader = csv.DictReader(f) + for row in reader: + channel = { + "name": row["Name"], + "frequency": int(float(row["Frequency"]) * 1000000), + "modulation": modulation_map[row["Mode"]], + } + to_integrate.append(channel) + +bookmarks.extend(to_integrate) +deduplicated = [dict(t) for t in {tuple(d.items()) for d in bookmarks}] + +with open("../bookmarks.json", "w") as f: + json.dump(deduplicated, f)