Created
October 12, 2017 21:40
-
-
Save meffie/c89cc7c69a89576055353aab4d77e11f to your computer and use it in GitHub Desktop.
csdb parser
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
#!/usr/bin/python | |
import re | |
import pprint | |
import urllib2 | |
from sh import rxdebug | |
def get_csdb(): | |
response = urllib2.urlopen('https://grand.central.org/dl/cellservdb/CellServDB') | |
return response.read() | |
def read_csdb(): | |
csdb = None | |
with open('CellServDB', 'r') as f: | |
csdb = f.read() | |
return csdb | |
def parse_csdb(csdb): | |
cells = [] | |
cell = None | |
for line in csdb.splitlines(): | |
m = re.match('\S*$', line) | |
if m: | |
continue | |
m = re.match('>(\S+)\s+#(.*)\s*$', line) | |
if m: | |
if cell: | |
cells.append(cell) | |
cell = {} | |
cell['name'] = m.group(1) | |
cell['desc'] = m.group(2) | |
cell['addrs'] = [] | |
continue | |
m = re.match('(\d+\.\d+\.\d+\.\d+)\s+#(.*)\s*$', line) | |
if m: | |
cell['addrs'].append((m.group(1),m.group(2))) | |
return cells | |
def get_version(addr): | |
version = rxdebug(addr, '7003', '-version') | |
print version | |
if __name__ == '__main__': | |
csdb = get_csdb() | |
#csdb = read_csdb() | |
cells = parse_csdb(csdb) | |
pprint.pprint(cells) | |
for cell in cells: | |
print cell['name'], ":", cell['desc'] | |
#get_version(cell['addrs'][0][0]) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment