Skip to content

Commit

Permalink
Merge pull request travisgoodspeed#858 from KD4Z/dmrmarc_json
Browse files Browse the repository at this point in the history
Change dmr-marc user pull format from CSV to JSON Fixes travisgoodspeed#857
  • Loading branch information
travisgoodspeed authored Mar 12, 2018
2 parents 500740d + 27315d7 commit 8146c85
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 4 deletions.
7 changes: 5 additions & 2 deletions applet/src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,10 @@ void draw_adhoc_statusline()
// ch_freqoff = ((ch_rxfreq - ch_txfreq) / 100000);

user_t usr; // reference user DB


channel_info_t *ci = &current_channel_info ;
BOOL fIsWideBandwidth = ( ci->mode >> 3 ) & 0x1 ;

//========================================================================================================================//
// First build general mode independent status info // RPT shift and Mic gain
//========================================================================================================================//
Expand Down Expand Up @@ -784,7 +787,7 @@ void draw_adhoc_statusline()
} else {
strcpy(top_status, "FM"); // init FM string
}
if (global_addl_config.fm_bw == 0) { strcpy(fm_bw_stat, "|N"); } else { strcpy(fm_bw_stat, "|W"); }
if (fIsWideBandwidth) { strcpy(fm_bw_stat, "|W"); } else { strcpy(fm_bw_stat, "|N"); }

strcat(top_status, fm_bw_stat); // |N or |W
strcat(top_status, ch_offset); // |-R| or |=>| simplex
Expand Down
4 changes: 2 additions & 2 deletions db/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ dmrmarc2.tmp: dmrmarc.tmp
awk -F, -f insert_nick.awk <$< >$@

dmrmarc.tmp:
curl $(CURL_FLAGS) 'http://www.dmr-marc.net/cgi-bin/trbo-database/datadump.cgi?table=users&format=csv&header=0' | perl -pe 's,<br/>,,' >$@
python2 get_dmrmarc_json.py >$@ 2>get_dmrmarc.errors

reflector.tmp:
curl $(CURL_FLAGS) 'http://registry.dstar.su/reflector.db' | perl -pe '$$_ = "" if ( $$. == 1 ); s#@#,#; s#@.*#,,,,,,#' >$@

Expand Down
74 changes: 74 additions & 0 deletions db/get_dmrmarc_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# KD4Z
# dmr-marc decided to stop offering CSV output format, so json here we come

import requests
import sys

def noCommas(field):
try:

if field is None:
return ""

field = field.encode('ascii', 'ignore').decode('ascii')



except (UnicodeEncodeError, TypeError, AttributeError):
pass

return removeSubstr(field,",")

def removeSubstr(field, subfield):

try:

field = field.replace(","," ").strip()

except (UnicodeEncodeError, TypeError, AttributeError):
pass

return field

def dmrmarc_json():


myreq = requests.get('http://www.dmr-marc.net/cgi-bin/trbo-database/datadump.cgi?table=users&format=json')

dmrmarc = myreq.json()

for user in dmrmarc['users']:

try:
sir = noCommas(user["surname"])
fullname = noCommas(user["name"])
if len(sir) > 0:
fullname = fullname + " " + sir

line = "{0},{1},{2},{3},{4},{5},".format(
user["radio_id"],
noCommas(user["callsign"]),
fullname,
noCommas(user["city"]),
noCommas(user["state"]),
noCommas(user["country"]))

print(line)


except (UnicodeEncodeError, TypeError, AttributeError):
sys.exc_clear()


def main():
try:
dmrmarc_json()()

except Exception:
pass


if __name__ == '__main__':
main()

0 comments on commit 8146c85

Please sign in to comment.