forked from travisgoodspeed/md380tools
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request travisgoodspeed#858 from KD4Z/dmrmarc_json
Change dmr-marc user pull format from CSV to JSON Fixes travisgoodspeed#857
- Loading branch information
Showing
3 changed files
with
81 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |