
    iP
                     N    d dl Z d dlmZ ddddddZd	Zd
 Zd ZddZddZd Z	y)    N)EXTERNAL_URLS
imdb_title	imdb_nameimdb_characterimdb_company
imdb_event)ttmnchcoevz3http://commons.wikimedia.org/wiki/Special:FilePath/c                 6    | d d }t         j                  |      S )N   )IMDB_PREFIX_TO_URL_IDget)imdb_item_id	id_prefixs     $/root/searxng/searx/external_urls.pyget_imdb_url_idr      s    Ra I $$Y//    c                     | j                  t              r| t        t              d  S | j                  d      r| t        d      d  S | S )NzFile:)
startswithHTTP_WIKIMEDIA_IMAGElen)urls    r   get_wikimedia_image_idr      sE    
~~*+3+,.//
~~g3w<>""Jr   c                     |!| dk(  rt        |      } n| dk(  rt        |      }t        j                  |       }|r,|d   j                  |      }|||j	                  d|      S |S y)a  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.
    Nimdb_idwikimedia_imageurlsz$1)r   r   r   r   replace)url_iditem_idalternativeurl_descriptionurl_templates        r   get_external_urlr'       s     Y$W-F((,W5G#''/O&v.22;?#"#++D'::r   c                     t        dd |      j                  dt        |             j                  dt        |            j                  dt        |            }|S )Nmapz${latitude}z${longitude}z${zoom})r'   r!   str)latitude	longitudeosm_zoomr$   r   s        r   get_earth_coordinates_urlr.   8   sJ    k2	H	.	Y	0	CM	*	  Jr   c                     	 t        |       }t        dt        dt        ddt	        j
                  d|z        z  z
                    S # t        $ r Y yw xY w)u?  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
    r      gn?gjt\l@)floatmaxminroundmathlog
ValueError)areaamounts     r   area_to_osm_zoomr:   B   sS    .t1c"eBDHHWv=M4N)N$NOPQQ s   AA 	AA)default)
r5   
searx.datar   r   r   r   r   r'   r.   r:    r   r   <module>r>      sH     $ 



  M 0
0r   