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

Functions

 get_imdb_url_id (imdb_item_id)
 
 get_wikimedia_image_id (url)
 
 get_external_url (url_id, item_id, alternative="default")
 
 get_earth_coordinates_url (latitude, longitude, osm_zoom, alternative='default')
 
 area_to_osm_zoom (area)
 

Variables

dict IMDB_PREFIX_TO_URL_ID
 
str HTTP_WIKIMEDIA_IMAGE = 'http://commons.wikimedia.org/wiki/Special:FilePath/'
 

Function Documentation

◆ area_to_osm_zoom()

searx.external_urls.area_to_osm_zoom ( area)
Convert an area in km² into an OSM zoom. Less reliable if the shape is not round.

logarithm regression using these data:
 * 9596961 -> 4 (China)
 * 3287263 -> 5 (India)
 * 643801 -> 6 (France)
 * 6028 -> 9
 * 1214 -> 10
 * 891 -> 12
 * 12 -> 13

In WolframAlpha:
    >>> log fit {9596961,15},{3287263, 14},{643801,13},{6028,10},{1214,9},{891,7},{12,6}

with 15 = 19-4 (China); 14 = 19-5 (India) and so on

Args:
    area (int,float,str): area in km²

Returns:
    int: OSM zoom or 19 in area is not a number

Definition at line 66 of file external_urls.py.

66def area_to_osm_zoom(area):
67 """Convert an area in km² into an OSM zoom. Less reliable if the shape is not round.
68
69 logarithm regression using these data:
70 * 9596961 -> 4 (China)
71 * 3287263 -> 5 (India)
72 * 643801 -> 6 (France)
73 * 6028 -> 9
74 * 1214 -> 10
75 * 891 -> 12
76 * 12 -> 13
77
78 In WolframAlpha:
79 >>> log fit {9596961,15},{3287263, 14},{643801,13},{6028,10},{1214,9},{891,7},{12,6}
80
81 with 15 = 19-4 (China); 14 = 19-5 (India) and so on
82
83 Args:
84 area (int,float,str): area in km²
85
86 Returns:
87 int: OSM zoom or 19 in area is not a number
88 """
89 try:
90 amount = float(area)
91 return max(0, min(19, round(19 - 0.688297 * math.log(226.878 * amount))))
92 except ValueError:
93 return 19

◆ get_earth_coordinates_url()

searx.external_urls.get_earth_coordinates_url ( latitude,
longitude,
osm_zoom,
alternative = 'default' )

Definition at line 56 of file external_urls.py.

56def get_earth_coordinates_url(latitude, longitude, osm_zoom, alternative='default'):
57 url = (
58 get_external_url('map', None, alternative)
59 .replace('${latitude}', str(latitude))
60 .replace('${longitude}', str(longitude))
61 .replace('${zoom}', str(osm_zoom))
62 )
63 return url
64
65

◆ get_external_url()

searx.external_urls.get_external_url ( url_id,
item_id,
alternative = "default" )
Return an external URL or None if url_id is not found.

url_id can take value from data/external_urls.json
The "imdb_id" value is automatically converted according to the item_id value.

If item_id is None, the raw URL with the $1 is returned.

Definition at line 32 of file external_urls.py.

32def get_external_url(url_id, item_id, alternative="default"):
33 """Return an external URL or None if url_id is not found.
34
35 url_id can take value from data/external_urls.json
36 The "imdb_id" value is automatically converted according to the item_id value.
37
38 If item_id is None, the raw URL with the $1 is returned.
39 """
40 if item_id is not None:
41 if url_id == 'imdb_id':
42 url_id = get_imdb_url_id(item_id)
43 elif url_id == 'wikimedia_image':
44 item_id = get_wikimedia_image_id(item_id)
45
46 url_description = EXTERNAL_URLS.get(url_id)
47 if url_description:
48 url_template = url_description["urls"].get(alternative)
49 if url_template is not None:
50 if item_id is not None:
51 return url_template.replace('$1', item_id)
52 return url_template
53 return None
54
55

References searx.external_urls.get_imdb_url_id(), and searx.external_urls.get_wikimedia_image_id().

+ Here is the call graph for this function:

◆ get_imdb_url_id()

searx.external_urls.get_imdb_url_id ( imdb_item_id)

Definition at line 19 of file external_urls.py.

19def get_imdb_url_id(imdb_item_id):
20 id_prefix = imdb_item_id[:2]
21 return IMDB_PREFIX_TO_URL_ID.get(id_prefix)
22
23

Referenced by searx.external_urls.get_external_url().

+ Here is the caller graph for this function:

◆ get_wikimedia_image_id()

searx.external_urls.get_wikimedia_image_id ( url)

Definition at line 24 of file external_urls.py.

24def get_wikimedia_image_id(url):
25 if url.startswith(HTTP_WIKIMEDIA_IMAGE):
26 return url[len(HTTP_WIKIMEDIA_IMAGE) :]
27 if url.startswith('File:'):
28 return url[len('File:') :]
29 return url
30
31

Referenced by searx.external_urls.get_external_url().

+ Here is the caller graph for this function:

Variable Documentation

◆ HTTP_WIKIMEDIA_IMAGE

str searx.external_urls.HTTP_WIKIMEDIA_IMAGE = 'http://commons.wikimedia.org/wiki/Special:FilePath/'

Definition at line 16 of file external_urls.py.

◆ IMDB_PREFIX_TO_URL_ID

dict searx.external_urls.IMDB_PREFIX_TO_URL_ID
Initial value:
1= {
2 'tt': 'imdb_title',
3 'mn': 'imdb_name',
4 'ch': 'imdb_character',
5 'co': 'imdb_company',
6 'ev': 'imdb_event',
7}

Definition at line 9 of file external_urls.py.