9IMDB_PREFIX_TO_URL_ID = {
12 'ch':
'imdb_character',
16HTTP_WIKIMEDIA_IMAGE =
'http://commons.wikimedia.org/wiki/Special:FilePath/'
20 id_prefix = imdb_item_id[:2]
21 return IMDB_PREFIX_TO_URL_ID.get(id_prefix)
25 if url.startswith(HTTP_WIKIMEDIA_IMAGE):
26 return url[len(HTTP_WIKIMEDIA_IMAGE) :]
27 if url.startswith(
'File:'):
28 return url[len(
'File:') :]
33 """Return an external URL or None if url_id is not found.
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.
38 If item_id is None, the raw URL with the $1 is returned.
40 if item_id
is not None:
41 if url_id ==
'imdb_id':
43 elif url_id ==
'wikimedia_image':
46 url_description = EXTERNAL_URLS.get(url_id)
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)
58 get_external_url(
'map',
None, alternative)
59 .replace(
'${latitude}', str(latitude))
60 .replace(
'${longitude}', str(longitude))
61 .replace(
'${zoom}', str(osm_zoom))
67 """Convert an area in km² into an OSM zoom. Less reliable if the shape is not round.
69 logarithm regression using these data:
70 * 9596961 -> 4 (China)
71 * 3287263 -> 5 (India)
72 * 643801 -> 6 (France)
79 >>> log fit {9596961,15},{3287263, 14},{643801,13},{6028,10},{1214,9},{891,7},{12,6}
81 with 15 = 19-4 (China); 14 = 19-5 (India) and so on
84 area (int,float,str): area in km²
87 int: OSM zoom or 19 in area is not a number
91 return max(0, min(19, round(19 - 0.688297 * math.log(226.878 * amount))))
get_imdb_url_id(imdb_item_id)
get_external_url(url_id, item_id, alternative="default")
get_earth_coordinates_url(latitude, longitude, osm_zoom, alternative='default')
get_wikimedia_image_id(url)