mirror of
				https://github.com/searxng/searxng.git
				synced 2025-10-31 10:37:06 -04:00 
			
		
		
		
	[fix] pep8
This commit is contained in:
		
							parent
							
								
									48058075c0
								
							
						
					
					
						commit
						672f1c674c
					
				| @ -16,13 +16,14 @@ categories = ['map'] | |||||||
| paging = False | paging = False | ||||||
| 
 | 
 | ||||||
| # search-url | # search-url | ||||||
| base_url = 'https://nominatim.openstreetmap.org/search/{query}?format=json&polygon_geojson=1&addressdetails=1' | base_url = 'https://nominatim.openstreetmap.org/' | ||||||
|  | search_string = 'search/{query}?format=json&polygon_geojson=1&addressdetails=1' | ||||||
| result_base_url = 'https://openstreetmap.org/{osm_type}/{osm_id}' | result_base_url = 'https://openstreetmap.org/{osm_type}/{osm_id}' | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| # do search-request | # do search-request | ||||||
| def request(query, params): | def request(query, params): | ||||||
|     params['url'] = base_url.format(query=query) |     params['url'] = base_url + search_string.format(query=query) | ||||||
| 
 | 
 | ||||||
|     # using searx User-Agent |     # using searx User-Agent | ||||||
|     params['headers']['User-Agent'] = searx_useragent() |     params['headers']['User-Agent'] = searx_useragent() | ||||||
| @ -71,8 +72,8 @@ def response(resp): | |||||||
|             address.update({'house_number': address_raw.get('house_number'), |             address.update({'house_number': address_raw.get('house_number'), | ||||||
|                            'road': address_raw.get('road'), |                            'road': address_raw.get('road'), | ||||||
|                            'locality': address_raw.get('city', |                            'locality': address_raw.get('city', | ||||||
|                                        address_raw.get('town', |                                        address_raw.get('town',          # noqa | ||||||
|                                        address_raw.get('village'))), |                                        address_raw.get('village'))),    # noqa | ||||||
|                            'postcode': address_raw.get('postcode'), |                            'postcode': address_raw.get('postcode'), | ||||||
|                            'country': address_raw.get('country'), |                            'country': address_raw.get('country'), | ||||||
|                            'country_code': address_raw.get('country_code')}) |                            'country_code': address_raw.get('country_code')}) | ||||||
|  | |||||||
| @ -19,22 +19,25 @@ language_support = True | |||||||
| number_of_results = 10 | number_of_results = 10 | ||||||
| 
 | 
 | ||||||
| # search-url | # search-url | ||||||
| search_url = 'https://photon.komoot.de/api/?{query}&limit={limit}' | base_url = 'https://photon.komoot.de/' | ||||||
|  | search_string = 'api/?{query}&limit={limit}' | ||||||
| result_base_url = 'https://openstreetmap.org/{osm_type}/{osm_id}' | result_base_url = 'https://openstreetmap.org/{osm_type}/{osm_id}' | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| # do search-request | # do search-request | ||||||
| def request(query, params): | def request(query, params): | ||||||
|     params['url'] = search_url.format(query=urlencode({'q': query}), |     params['url'] = base_url +\ | ||||||
|                                       limit=number_of_results) |         search_string.format(query=urlencode({'q': query}), | ||||||
|  |                              limit=number_of_results) | ||||||
| 
 | 
 | ||||||
|     if params['language'] != 'all': |     if params['language'] != 'all': | ||||||
|         params['url'] = params['url'] + "&lang=" + params['language'].replace('_', '-') |         params['url'] = params['url'] +\ | ||||||
|  |             "&lang=" + params['language'].replace('_', '-') | ||||||
| 
 | 
 | ||||||
|     # using searx User-Agent |     # using searx User-Agent | ||||||
|     params['headers']['User-Agent'] = searx_useragent() |     params['headers']['User-Agent'] = searx_useragent() | ||||||
|      | 
 | ||||||
|     # FIX: SSLError: [Errno 1] _ssl.c:510: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed |     # FIX: SSLError: SSL3_GET_SERVER_CERTIFICATE:certificate verify failed | ||||||
|     params['verify'] = False |     params['verify'] = False | ||||||
| 
 | 
 | ||||||
|     return params |     return params | ||||||
| @ -47,15 +50,15 @@ def response(resp): | |||||||
| 
 | 
 | ||||||
|     # parse results |     # parse results | ||||||
|     for r in json.get('features', {}): |     for r in json.get('features', {}): | ||||||
|      | 
 | ||||||
|         properties = r.get('properties') |         properties = r.get('properties') | ||||||
|          | 
 | ||||||
|         if not properties: |         if not properties: | ||||||
|             continue |             continue | ||||||
|          | 
 | ||||||
|         # get title |         # get title | ||||||
|         title = properties['name'] |         title = properties['name'] | ||||||
|          | 
 | ||||||
|         # get osm-type |         # get osm-type | ||||||
|         if properties.get('osm_type') == 'N': |         if properties.get('osm_type') == 'N': | ||||||
|             osm_type = 'node' |             osm_type = 'node' | ||||||
| @ -66,7 +69,7 @@ def response(resp): | |||||||
|         else: |         else: | ||||||
|             # continue if invalide osm-type |             # continue if invalide osm-type | ||||||
|             continue |             continue | ||||||
|              | 
 | ||||||
|         url = result_base_url.format(osm_type=osm_type, |         url = result_base_url.format(osm_type=osm_type, | ||||||
|                                      osm_id=properties.get('osm_id')) |                                      osm_id=properties.get('osm_id')) | ||||||
| 
 | 
 | ||||||
| @ -74,14 +77,20 @@ def response(resp): | |||||||
|                'id': properties.get('osm_id')} |                'id': properties.get('osm_id')} | ||||||
| 
 | 
 | ||||||
|         geojson = r.get('geometry') |         geojson = r.get('geometry') | ||||||
|          | 
 | ||||||
|         if  properties.get('extent'): |         if properties.get('extent'): | ||||||
|             boundingbox = [properties.get('extent')[3], properties.get('extent')[1], properties.get('extent')[0], properties.get('extent')[2]] |             boundingbox = [properties.get('extent')[3], | ||||||
|  |                            properties.get('extent')[1], | ||||||
|  |                            properties.get('extent')[0], | ||||||
|  |                            properties.get('extent')[2]] | ||||||
|         else: |         else: | ||||||
|             # TODO: better boundingbox calculation |             # TODO: better boundingbox calculation | ||||||
|             boundingbox = [geojson['coordinates'][1], geojson['coordinates'][1], geojson['coordinates'][0], geojson['coordinates'][0]] |             boundingbox = [geojson['coordinates'][1], | ||||||
|          |                            geojson['coordinates'][1], | ||||||
|         # TODO: address calculation |                            geojson['coordinates'][0], | ||||||
|  |                            geojson['coordinates'][0]] | ||||||
|  | 
 | ||||||
|  |         # address calculation | ||||||
|         address = {} |         address = {} | ||||||
| 
 | 
 | ||||||
|         # get name |         # get name | ||||||
| @ -90,14 +99,14 @@ def response(resp): | |||||||
|            properties.get('osm_key') == 'tourism' or\ |            properties.get('osm_key') == 'tourism' or\ | ||||||
|            properties.get('osm_key') == 'leisure': |            properties.get('osm_key') == 'leisure': | ||||||
|             address = {'name': properties.get('name')} |             address = {'name': properties.get('name')} | ||||||
|                  | 
 | ||||||
|         # add rest of adressdata, if something is already found |         # add rest of adressdata, if something is already found | ||||||
|         if address.get('name'): |         if address.get('name'): | ||||||
|             address.update({'house_number': properties.get('housenumber'), |             address.update({'house_number': properties.get('housenumber'), | ||||||
|                            'road': properties.get('street'), |                            'road': properties.get('street'), | ||||||
|                            'locality': properties.get('city', |                            'locality': properties.get('city', | ||||||
|                                        properties.get('town', |                                        properties.get('town',           # noqa | ||||||
|                                        properties.get('village'))), |                                        properties.get('village'))),     # noqa | ||||||
|                            'postcode': properties.get('postcode'), |                            'postcode': properties.get('postcode'), | ||||||
|                            'country': properties.get('country')}) |                            'country': properties.get('country')}) | ||||||
|         else: |         else: | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user