.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.apple_maps Namespace Reference

Functions

 obtain_token ()
 
 request (query, params)
 
 response (resp)
 

Variables

dict about
 
dict token = {'value': '', 'last_updated': None}
 
list categories = ['map']
 
bool paging = False
 
str search_url = "https://api.apple-mapkit.com/v1/search?{query}&mkjsVersion=5.72.53"
 

Detailed Description

Apple Maps

Function Documentation

◆ obtain_token()

searx.engines.apple_maps.obtain_token ( )

Definition at line 28 of file apple_maps.py.

28def obtain_token():
29 update_time = time() - (time() % 1800)
30 try:
31 # use duckduckgo's mapkit token
32 token_response = http_get('https://duckduckgo.com/local.js?get_mk_token=1', timeout=2.0)
33 actual_token = http_get(
34 'https://cdn.apple-mapkit.com/ma/bootstrap?apiVersion=2&mkjsVersion=5.72.53&poi=1',
35 timeout=2.0,
36 headers={'Authorization': 'Bearer ' + token_response.text},
37 )
38 token['value'] = loads(actual_token.text)['authInfo']['access_token']
39 token['last_updated'] = update_time
40 # pylint: disable=bare-except
41 except:
42 pass
43 return token
44
45

Referenced by searx.engines.apple_maps.request().

+ Here is the caller graph for this function:

◆ request()

searx.engines.apple_maps.request ( query,
params )

Definition at line 46 of file apple_maps.py.

46def request(query, params):
47 if time() - (token['last_updated'] or 0) > 1800:
48 obtain_token()
49
50 params['url'] = search_url.format(query=urlencode({'q': query, 'lang': params['language']}))
51
52 params['headers'] = {'Authorization': 'Bearer ' + token['value']}
53
54 return params
55
56

References searx.engines.apple_maps.obtain_token().

+ Here is the call graph for this function:

◆ response()

searx.engines.apple_maps.response ( resp)

Definition at line 57 of file apple_maps.py.

57def response(resp):
58 results = []
59
60 resp_json = loads(resp.text)
61
62 user_language = resp.search_params['language']
63
64 for result in resp_json['results']:
65 boundingbox = None
66 if 'displayMapRegion' in result:
67 box = result['displayMapRegion']
68 boundingbox = [box['southLat'], box['northLat'], box['westLng'], box['eastLng']]
69
70 links = []
71 if 'telephone' in result:
72 telephone = result['telephone']
73 links.append(
74 {
75 'label': get_key_label('phone', user_language),
76 'url': 'tel:' + telephone,
77 'url_label': telephone,
78 }
79 )
80 if result.get('urls'):
81 url = result['urls'][0]
82 links.append(
83 {
84 'label': get_key_label('website', user_language),
85 'url': url,
86 'url_label': url,
87 }
88 )
89
90 results.append(
91 {
92 'template': 'map.html',
93 'type': result.get('poiCategory'),
94 'title': result['name'],
95 'links': links,
96 'latitude': result['center']['lat'],
97 'longitude': result['center']['lng'],
98 'url': result['placecardUrl'],
99 'boundingbox': boundingbox,
100 'geojson': {'type': 'Point', 'coordinates': [result['center']['lng'], result['center']['lat']]},
101 'address': {
102 'name': result['name'],
103 'house_number': result.get('subThoroughfare'),
104 'road': result.get('thoroughfare'),
105 'locality': result.get('locality'),
106 'postcode': result.get('postCode'),
107 'country': result.get('country'),
108 },
109 }
110 )
111
112 return results

Variable Documentation

◆ about

dict searx.engines.apple_maps.about
Initial value:
1= {
2 "website": 'https://www.apple.com/maps/',
3 "wikidata_id": 'Q276101',
4 "official_api_documentation": None,
5 "use_official_api": True,
6 "require_api_key": False,
7 "results": 'JSON',
8}

Definition at line 11 of file apple_maps.py.

◆ categories

list searx.engines.apple_maps.categories = ['map']

Definition at line 22 of file apple_maps.py.

◆ paging

bool searx.engines.apple_maps.paging = False

Definition at line 23 of file apple_maps.py.

◆ search_url

str searx.engines.apple_maps.search_url = "https://api.apple-mapkit.com/v1/search?{query}&mkjsVersion=5.72.53"

Definition at line 25 of file apple_maps.py.

◆ token

dict searx.engines.apple_maps.token = {'value': '', 'last_updated': None}

Definition at line 20 of file apple_maps.py.