def _overpass_filter_highway_upto_level(level):
    """
    Generates an overpass filter (See https://wiki.openstreetmap.org/wiki/Overpass_API/Language_Guide)
    for selecting only streets upto importance `level`.

    Also deselects streets not relevant for public routing, e.g. provate pr driveways.
    """
    street_impotance_levels = ['motorway', 'trunk', 'primary', 'secondary', 'tertiary']
    assert level in street_impotance_levels

    highway_types_to_include = street_impotance_levels[:street_impotance_levels.index(level)+1]
    custom_filter='|'.join(highway_types_to_include)
    return f'["area"!~"yes"]["highway"~"{custom_filter}"]'\
           f'["motor_vehicle"!~"no"]["motorcar"!~"no"]["access"!~"private"]'\
           f'["service"!~"parking|parking_aisle|driveway|private|emergency_access"]'