Ejemplo n.º 1
0
def build_dict(path, path_build):
    format = ">2I"
    keys = []
    values = []
    file_handler = open(path, 'rb')
    for line in file_handler:
        line = line.strip('/r/n')
        arr = line.split('\t')
        try:
            if len(arr) == 3:
                keys.append(arr[0].decode("utf-8"))
                values.append([int(arr[1]), int(arr[2])])
            else:
                continue
        except:
            continue
    data = zip(keys, values)
    record = RecordDAWG(format, data)
    with open(path_build, 'wb') as f:
        record.write(f)
Ejemplo n.º 2
0
                nameIdMap[short_name] = []
            #print short_name, region_id, region_id_online
            nameIdMap[short_name].append([region_id, region_id_online])
    return nameIdMap


if __name__ == '__main__':
    #"654226", "和布克赛尔蒙古自治县", "和布克赛尔县", "0", "312216", "65", "amqp://*****:*****@120.27.247.47:5672/%2F"
    build_file = 'region_all.dawg'

    #generate dict
    format = ">2I"
    keys = []
    values = []

    nameIdMap = get_region_list()
    for k in nameIdMap.keys():
        t = nameIdMap[k]
        for v in t:
            if v[0] and v[1]:
                keys.append(k)
                values.append([int(v[0]), int(v[1])])

    print len(values), len(keys)
    for x in range(0, len(values)):
        print keys[x], values[x]
    data = zip(keys, values)
    record = RecordDAWG(format, data)
    with open(build_file, 'wb') as f:
        record.write(f)