Utility for fixing ...
 
Notifications
Clear all

Utility for fixing the radioid contact list


Jed Baer
(@kd0ymg)
Eminent Member Trial
Joined: 5 months ago
Posts: 27
Topic starter  

I haven't dug into the contact database from radioid in a while, but I suspect the problem I worked around is still there. What happens is they allow the city field to contain commas, which is probably reasonable from a postal address point of view. But it creates a problem in their CSV file dumps. CSV is "comma separated values". What happens is that a user will enter a long "city" name, with multiple locations names using commas, something like "Televideo, Bahama, DelNorte, ZZ098", and I recall the longest one I found was 6 items. radioid doesn't use quotation marks to enclose the fields in the CSV file, so fields coming after the city name are moved over by the number of positions equal to the extra items in the city field. So, you end up with invalid country names, for example.

I solved this for myself, by using the JSON data dump instead of the CSV file. I wrote a script to convert it to CSV, and select the fields used by my Anytone AT-D878. This will work for any radio using the same fields, in the same order, as the Anytone, or which uses the field header to identify which fields are present in which columns.

This could be easily modified for other radios, such as the MD-380, but there's a catch in that the contact database is possibly too large.

I know that for the MD-380, Dave Haan wrote A Database Editor Program for MD380/390 DMR Radios, but I don't know whether it'll accept a CSV file from local storage, or use a quote-enclosed CSV file. It "compresses" the contact list by substituting ISO country codes for country names, and some other things. If the country code is garbage, then that part of the program won't do anything.

Anyways, here's my little script. This runs on Linux, but I figure it should be convertible to PowerShell for windows, provided the wget, awk, and jq utilities are available, or similar function is provided by other utilities. The "todos" wouldn't be needed running on Windows.

#!/bin/bash
#
# Author: Jed Baer -- KD0YMG
# A utility to convert the radioid DMR contact database from JSON to CSV
# with fields for Anytone AT-D878 and similar

# Retrieve the contact database in JSON form
wget  https://www.radioid.net/static/users.json  -O users.json

# Use the jq utility to transform to CSV, extracting fields for Anytone
cat users.json | jq -r '.users[] | [.radio_id, .callsign, (.fname + " " + .surname), .city, .state, .country, .remarks, "Private Call", "None"] | @csv' > json_users.csv

# Add record numbers as first column
cat json_users.csv | awk '{printf("\"%d\",%s\n",NR,$0)}' > json_users_n.csv

# Add header line
echo '"No.","Radio ID","Callsign","Name","City","State","Country","Remarks","Call Type","Call Alert"' > json_users_hdr.csv
cat json_users_n.csv >> json_users_hdr.csv

# Transform to DOS type line separator (CRLF)
todos json_users_hdr.csv

A nice enhancement would be to add some filtering, maybe similar to what radioid provides for location selection. I probably won't worry about that until my radio barfs on the size of the contact list.

Feel free to use, copy, enhance, whatever.


Quote
Share: