예제 #1
0
 def test_finding_address(self):
     test_string = """
       <way id="102650050" version="4" timestamp="2016-10-22T22:54:55Z">
         <nd ref="1185535609"/>
         <nd ref="1185535662"/>
         <nd ref="1185535654"/>
         <nd ref="1185535647"/>
         <nd ref="1185535609"/>
         <tag k="name" v="вилла Яффа"/>
         <tag k="building" v="yes"/>
         <tag k="addr:city" v="Калининград"/>
         <tag k="addr:street" v="улица Кутузова"/>
         <tag k="addr:housename" v="вилла Яффа"/>
         <tag k="addr:housenumber" v="10"/>
       </way>
     """
     address = DataBase.cut_info(test_string)[0]
     self.assertEqual(address, "калининград, улица кутузова, 10")
예제 #2
0
        lats = []
        lons = []
        for coord_tuple in coords:
            if coord_tuple:
                lat, lon = coord_tuple[0], coord_tuple[1]
                lats.append(float(lat))
                lons.append(float(lon))
        if lats and lons:
            return sum(lats) / len(lats), sum(lons) / len(lons)
        else:
            return 0, 0


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-c', '--city', type=str, action='store')
    parser.add_argument('-s', '--street', type=str, action='store')
    parser.add_argument('-hn', '--house_number', type=str, action='store')
    parser.add_argument('-p',
                        '--path',
                        type=str,
                        action='store',
                        help="folder to the file prepared by prepare_osm")
    args = parser.parse_args().__dict__
    address = args['city'] + ", " + args['street'] + ", " + args['house_number']
    s = Searcher(args["path"])
    print(
        DataBase.return_json_address(
            args['city'], args['street'], args['house_number'],
            Searcher.get_median(s.search_nodes(address))))
예제 #3
0
 def test_normalizing_input(self):
     normed = DataBase.normalize_input("</NY, Houston avenue, 12.//")
     self.assertEqual(normed, "ny, houston avenue, 12")
예제 #4
0
 def test__json(self):
     exp = "{\"address\": {\"city\": \"kgrad\", \"street\": \"kanta\", \"house\": \"1\"}," \
           " \"coordinates\": {\"lat\": 1.0, \"lon\": 2.0, \"both\": [1.0, 2.0]}}"
     self.assertEqual(
         DataBase.return_json_address("kgrad", "kanta", "1", [1.0, 2.0]),
         exp)
예제 #5
0
 def test_skipping_new_line(self):
     normed = DataBase.normalize_input("</NY, Houston avenue, 12.//\n")
     self.assertEqual(normed, "ny, houston avenue, 12")
예제 #6
0
    parser.add_argument('-hn', '--house_number', type=str, action='store')
    parser.add_argument('-p', '--path', type=str, action='store',
                        help="path to save downloaded data")
    parser.add_argument('-r', '--regime', type=str, action='store',
                        choices=["region", "russia"])
    args = parser.parse_args().__dict__
    street = args['street']
    house_number = args['house_number']
    city = args['city']
    regime = args["regime"]
    path = args["path"]
    address = city + ", " + street + ", " + house_number
    if regime == "russia":
        links_to_download = russia
    else:
        links_to_download = region
    if not os.path.isdir(os.path.join(path, 'geodata')):
        Downloader.download_bz2(links_to_download, 'geodata')
    if not os.path.isdir(os.path.join(path, 'prepared')):
        for file in os.listdir(os.path.join(path, 'geodata')):
            if file.endswith(".txt"):
                print(f"preparing file: {os.path.join(path, 'geodata', file)}")
                db = DataBase(os.path.join(path, 'geodata', file),
                              os.path.join(path, 'prepared', file))
                s = Searcher(os.path.join(path, 'prepared', file))
    for file in os.listdir(os.path.join(path, 'prepared')):
        print("Created Searcher")
        s = Searcher(os.path.join(path, 'prepared', file))
        print(DataBase.return_json_address(args['city'], args['street'],
                                           args['house_number'], Searcher.get_median(s.search_nodes(address))))