File size: 1,128 Bytes
d710a81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from __future__ import annotations

from _overpass_utils import (
    CHATBOT_SERVICE_DIR,
    build_arg_parser,
    build_india_query,
    fetch_elements,
    normalize_row,
    print_summary,
    write_rows,
)


DEFAULT_OUTPUT = CHATBOT_SERVICE_DIR / 'data' / 'emergency' / 'fire_stations.csv'
SELECTORS = [
    'node["amenity"="fire_station"](area.india);',
    'way["amenity"="fire_station"](area.india);',
    'relation["amenity"="fire_station"](area.india);',
]


def main() -> None:
    parser = build_arg_parser('Fetch India fire station data from Overpass.', DEFAULT_OUTPUT)
    args = parser.parse_args()

    query = build_india_query(SELECTORS, timeout=args.timeout)
    elements = fetch_elements(query, endpoint=args.endpoint, timeout=args.timeout, retries=args.retries)
    rows = [
        row
        for element in elements
        if (row := normalize_row(element, default_category='fire_station', fallback_name='Unnamed fire station')) is not None
    ]
    count = write_rows(args.output, rows)
    print_summary(label='fire service', count=count, output=args.output)


if __name__ == '__main__':
    main()