def save_phonebook_memory(): query = "select pb_id, sim_num from phonebook" pb_result_set = dbio.query_database(query,"spm") phonebook = {} for pb_id, sim_num in pb_result_set: phonebook[pb_id] = sim_num phonebook_inv = {} for pb_id, sim_num in pb_result_set: phonebook_inv[sim_num] = pb_id mc.set("phonebook",phonebook) mc.set("phonebook_inv",phonebook_inv)
def get_network_info(): sc = common.get_config_handle() # mc = common.get_mc_server() site_code = sc['coordinfo']['name'] # get info from mysql tables query = ("select r.name, r.xbee_addr_short, r.xbee_addr_long from " "gateways g inner join routers r on g.gateway_id = r.gateway_id " "where g.code = '%s';") % (site_code) router_info = dbio.query_database(query, "gni") # print router_info # routers = pd.DataFrame(columns = ['name','addr_short','addr_long']) network_info = {} network_info['site_code'] = site_code network_info['router_name_by_addr_long'] = {} network_info['router_name_by_addr_short'] = {} network_info['addr_short_list'] = [] network_info['addr_long_list'] = [] network_info['router_addr_long_by_name'] = {} network_info['router_addr_short_by_name'] = {} for name, addr_short, addr_long in router_info: addr_long_packed = struct.pack('>q', int(addr_long, 16)) network_info['router_name_by_addr_long'][addr_long_packed] = name network_info['router_name_by_addr_short'][addr_short] = name network_info['addr_short_list'].append(addr_short) network_info['addr_long_list'].append(addr_long_packed) network_info['router_addr_long_by_name'][name] = addr_long_packed network_info['router_addr_short_by_name'][name] = addr_short print(network_info) common.mc.set('network_info', network_info)