
    i]              	       (   U d Z g dZddlmZ ddlZddlZddlZddlZddlm	Z	 ddl
Z
ddlZ
ddlZ
ddlZ
ddlZddlZddlmZ ddlmZmZ ddlmZ dd	lmZmZ daedz  ed
<   	 dZd ZdefdZdddedz  fdZ  G d dejB                  d      Z"ejF                  d   Z$ejF                  d   Z% G d dejB                        Z&ejF                  d   Z'ejP                  ed<    ejR                  e'      Z*ejV                  e,e'      ed<    G d dejB                  d      Z-ejF                  d   Z.ejP                  ed <    ejR                  e.      Z/ejV                  e,e.      ed!<    G d" d#ejB                  d      Z0ejF                  d$   Z1ejP                  ed%<    ejR                  e1      Z2ejV                  e,e1      ed&<    G d' d(ejB                  d      Z3ejF                  d)   Z4ejP                  ed*<    ejR                  e4      Z5ejV                  e,e4      ed+<    G d, d-ejB                        Z6ejF                  d.   Z7ejP                  ed/<   	  ejR                  e7      Z8ejV                  e,e7      ed0<   ejF                  d1   Z9ejP                  ed2<    ejR                  e9      Z:ejV                  e,e9      ed3<    G d4 d5ejB                        Z;ejF                  d6   Z<	 i d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXi dYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~ddddZ=	 e>dk(  r ejR                  e<      D ]  Z? e e?         e       Z@dZA eBeA        eBd eCeA      z          eBe@j                         j                                 eB        de@j                  j                   ZA eBeA        eBd eCeA      z          eB ee@j                               yy)z9Implementations used for weather conditions and forecast.)	
symbol_urlTemperaturePressure	WindSpeedRelativeHumidityCompassWeatherConditionTypeDateTimeGeoLocation    )ClassVarN)
quote_plus)network)ExpireCacheExpireCacheCfg)sxng_request)convert_to_siconvert_from_siWEATHER_DATA_CACHEz\https://raw.githubusercontent.com/nrkno/yr-weather-symbols/refs/heads/master/symbols/outlinec                  \    t         !t        j                  t        ddd            a t         S )Nr   i   i $ )nameMAX_VALUE_LENMAXHOLD_TIME)r   r   build_cacher        /root/searxng/searx/weather.pyget_WEATHER_DATA_CACHEr   /   s4     !(44)(1
 r   returnc                  t   ddl m}  ddlm} | j	                  t
        j                  j                  dd      g       } | j                  r | j                  d   dvr| j                  d   S t
        j                  j                  d      }|r|dvr|S |j                  t
              }|j                  }|r|dvr|S y)	Nr   )query)
ClientPrefq )allautolanguageen)searxr    searx.preferencesr!   RawTextQueryr   formget	languagesfrom_http_request
locale_tag)r    r!   search_langclient_prefs       r   _get_sxng_locale_tagr2   >   s    " ,|0044S"=rBE5??1-_Dq!!##''
3K{/9..|<K((K{/9r   	conditionr   c                    t         j                  |       }|yd}t               }t         d| d}|j                  ||      }||S t	        j                  |d      }|j
                  dk(  rS|j                  d	   }d
| dt        t        j                  |j                        d       }|j                  ||d|       |S )a  Returns ``data:`` URL for the weather condition symbol or ``None`` if
    the condition is not of type :py:obj:`WeatherConditionType`.

    If symbol (SVG) is not already in the :py:obj:`WEATHER_DATA_CACHE` its
    fetched from https://github.com/nrkno/yr-weather-symbols
    Nweather_symbol_url/z.svgctx   timeout   zContent-Typezdata:z;base64,zutf-8keyvalueexpirer8   )YR_WEATHER_SYMBOL_MAPr,   r   YR_WEATHER_SYMBOL_URLr   status_codeheadersstrbase64	b64encodecontentset)r3   fnamer8   cache
origin_urldata_urlresponsemimetypes           r   r   r   a   s     "%%i0E}
C"$E)*!E7$7Jyyy-H{{:q1Hs"##N38*HS1A1A(BRBR1SU\-],^_		j3	GOr   c                       e Zd ZU dZeed<   eed<   eed<   eed<   eed<   eed<   edej                  fd	       Zd
 Z
dej                  fdZededd fd       Zededeeef   fd       Zy)r
   z$Minimal implementation of Geocoding.r   latitude	longitude	elevationcountry_codetimezoner   c                 @    t        j                  | j                        S N)zoneinfoZoneInforU   selfs    r   rX   zGeoLocation.zoneinfo   s      //r   c                     | j                   S rW   )r   rZ   s    r   __str__zGeoLocation.__str__   s    yyr   c                    t               }d|v r+t        j                  j                  t               d      }|S t        j                  j                  | j                        D ]4  }	 t        j                  j                  | d| j                         }|c S  t        j                  dd      S # t        j                  $ r Y cw xY w)N-sep_r'   DE)	territory)r2   babelLocaleparser-   get_official_languagesrT   UnknownLocaleError)r[   sxng_taglocalelangs       r   rk   zGeoLocation.locale   s     ()(?\\''(<(>C'HFM OO::4;L;LM 	D++tfAd6G6G5H,IJ	 ||DD11 ++ s   '/B11CCsearch_termc                     d}t               }|j                  ||      }|s'| j                  |      }|j                  ||d|        | di |S )zFactory method to get a GeoLocation object by a search term.  If no
        location can be determined for the search term, a :py:obj:`ValueError`
        is thrown.
        weather_geolocation_by_queryr7   )rm   Nr=   r   )r   r,   _query_open_meteorI   )clsrm   r8   rK   	geo_propss        r   by_queryzGeoLocation.by_query   s]     -&( IIksI3	--+-FIII+YtIMYr   c                 8   dt        |       }t        j                  |d      }|j                  dk7  rt	        d| d      |j                         j                  d      }|st	        d| d      |d   }| j                  D ci c]  }|||   
 c}S c c}w )	Nz4https://geocoding-api.open-meteo.com/v1/search?name=r9   r:   r<   zunknown geo location: ''resultsr   )r   r   r,   rC   
ValueErrorjson__struct_fields__)rq   rm   urlresprv   location
field_names          r   rp   zGeoLocation._query_open_meteo   s    DZP[E\D]^{{3*s"6{m1EFF))+//),6{m1EFF1:CFCXCXYZ
HZ00YYYs   BN)__name__
__module____qualname____doc__rE   __annotations__floatpropertyrX   rY   r]   re   rf   rk   classmethodrs   dictrp   r   r   r   r
   r
      s    . IOM0(++ 0 02 2,  3  =    $ 	ZC 	ZDcN 	Z 	Zr   r
   T)kw_only)fulllongmediumshortUIc                       e Zd ZU dZej                  ed<   d Z	 	 d
deez  de	e
j                  z  ez  dz  defdZ	 	 d
deez  de	e
j                  z  ez  dz  defd	Zy)r	   a  Class to represent date & time.  Essentially, it is a wrapper that
    conveniently combines :py:obj:`datetime.datetime` and
    :py:obj:`babel.dates.format_datetime`.  A conversion of time zones is not
    provided (in the current version).

    The localized string representation can be obtained via the
    :py:obj:`DateTime.l10n` and :py:obj:`DateTime.l10n_date` methods, where the
    ``locale`` parameter defaults to the search language.  Alternatively, a
    :py:obj:`GeoLocation` or a :py:obj:`babel.Locale` instance can be passed
    directly. If the UI language is to be used, the string ``UI`` can be passed
    as the value for the ``locale``.
    datetimec                 "    | j                         S rW   l10nrZ   s    r   r]   zDateTime.__str__       yy{r   Nfmtrk   r   c                 F   t        |t              r|dk(  rt        j                         }nLt        |t              r|j                         }n+|)t        j                  j                  t               d      }t        j                  j                  | j                  ||      S )z(Localized representation of date & time.r   r_   r`   formatrk   )
isinstancerE   flask_babel
get_localer
   rk   re   rf   rg   r2   datesformat_datetimer   r[   r   rk   s      r   r   zDateTime.l10n   sy     fc"v~ ++-F,]]_F^\\''(<(>C'HF{{**4==V*TTr   c                 F   t        |t              r|dk(  rt        j                         }nLt        |t              r|j                         }n+|)t        j                  j                  t               d      }t        j                  j                  | j                  ||      S )z!Localized representation of date.r   r_   r`   r   )r   rE   r   r   r
   rk   re   rf   rg   r2   r   format_dater   r   s      r   	l10n_datezDateTime.l10n_date   sy     fc"v~ ++-F,]]_F^\\''(<(>C'HF{{&&t}}S&PPr   )r   N)r~   r   r   r   r   r   r]   DateTimeFormatsrE   DateTimeLocaleTypesre   rf   r
   r   r   r   r   r   r	   r	      s     
 &.JNUs"U $ell2[@4GU 
	U  &.JNQs"Q $ell2[@4GQ 
	Qr   r	   )   °C   °FKTemperatureUnitTEMPERATURE_UNITSc                       e Zd ZU dZeed<   eed<   dZee	   ed<   e
Zeee      ed<   d Zd Zded	efd
Z	 	 	 	 ddedz  dej"                  ez  dz  de	de	d	e	f
dZy)r   z\Class for converting temperature units and for string representation of
    measured values.valunitQ11579si_nameUNITSc                 d    | j                   | j                  vrt        d| j                          y Nzinvalid unit: r   r   rw   rZ   s    r   __post_init__zTemperature.__post_init__  -    99DJJ&~dii[9:: 'r   c                 "    | j                         S rW   r   rZ   s    r   r]   zTemperature.__str__  r   r   r   c                     || j                   k(  r| j                  S t        | j                  | j                   | j                        }t	        | j                  ||      S N)r   symbolr?   r   r   r   r   r   r[   r   si_vals      r   r?   zTemperature.value  D    49988Ot||DIITXXVt||DOOr   Nrk   templatenum_patternc                 J   t        |t              r|j                         }n+|)t        j                  j                  t               d      }|d}|j                  dv rd}t        j                  j                  | j                  |      ||      }|j                  ||      S )ar  Localized representation of a measured value.

        If the ``unit`` is not set, an attempt is made to determine a ``unit``
        matching the territory of the ``locale``.  If the locale is not set, an
        attempt is made to determine it from the HTTP request.

        The value is converted into the respective unit before formatting.

        The argument ``num_pattern`` is used to determine the string formatting
        of the numerical value:

        - https://babel.pocoo.org/en/latest/numbers.html#pattern-syntax
        - https://unicode.org/reports/tr35/tr35-numbers.html#Number_Format_Patterns

        The argument ``template`` specifies how the **string formatted** value
        and unit are to be arranged.

        - `Format Specification Mini-Language
          <https://docs.python.org/3/library/string.html#format-specification-mini-language>`.
        r_   r`   r   )USr   rk   r   r?   r   )r   r
   rk   re   rf   rg   r2   rd   numbersformat_decimalr?   r   r[   r   rk   r   r   val_strs         r   r   zTemperature.l10n  s    8 fk*]]_F^\\''(<(>C'HF<D6)--..tzz$/?Wb.cW488r   NNz{value} {unit}#,##0)r~   r   r   r   r   r   r   r   r   rE   r   r   tupler   r]   r?   re   rf   r
   r   r   r   r   r   r     s     
J
%GXc]%.?E8E/*+?;P/ Pe P (,48("&9$&9 {*T1&9 	&9
 &9 
&9r   r   )PahPazcm HgbarPressureUnitPRESSURE_UNITSc                       e Zd ZU dZeed<   eed<   dZee	   ed<   e
Zeee      ed<   d Zd Zded	efd
Z	 	 	 	 ddedz  dej"                  ez  dz  de	de	d	e	f
dZy)r   zYClass for converting pressure units and for string representation of
    measured values.r   r   Q44395r   r   c                 d    | j                   | j                  vrt        d| j                          y r   r   rZ   s    r   r   zPressure.__post_init__T  r   r   c                 "    | j                         S rW   r   rZ   s    r   r]   zPressure.__str__X  r   r   r   c                     || j                   k(  r| j                  S t        | j                  | j                   | j                        }t	        | j                  ||      S r   r   r   s      r   r?   zPressure.value[  r   r   Nrk   r   r   c                 *   t        |t              r|j                         }n+|)t        j                  j                  t               d      }|d}t        j                  j                  | j                  |      ||      }|j                  ||      S )Nr_   r`   r   r   r   r   r
   rk   re   rf   rg   r2   r   r   r?   r   r   s         r   r   zPressure.l10na  }     fk*]]_F^\\''(<(>C'HF<D--..tzz$/?Wb.cW488r   r   )r~   r   r   r   r   r   r   r   r   rE   r   r   r   r   r]   r?   re   rf   r
   r   r   r   r   r   r   J  s     
J
%GXc]%+9E8E,'(9;P, P5 P %)48("9T!9 {*T19 	9
 9 
9r   r   )m/szkm/hknmphzmi/hBftWindSpeedUnitWIND_SPEED_UNITSc                       e Zd ZU dZeed<   eed<   dZee	   ed<   e
Zeee      ed<   d Zd Zded	efd
Z	 	 	 	 ddedz  dej"                  ez  dz  de	de	d	e	f
dZy)r   a)  Class for converting speed or velocity units and for string
    representation of measured values.

    .. hint::

       Working with unit ``Bft`` (:py:obj:`searx.wikidata_units.Beaufort`) will
       throw a :py:obj:`ValueError` for egative values or values greater 16 Bft
       (55.6 m/s)
    r   r   Q182429r   r   c                 d    | j                   | j                  vrt        d| j                          y r   r   rZ   s    r   r   zWindSpeed.__post_init__  r   r   c                 "    | j                         S rW   r   rZ   s    r   r]   zWindSpeed.__str__  r   r   r   c                     || j                   k(  r| j                  S t        | j                  | j                   | j                        }t	        | j                  ||      S r   r   r   s      r   r?   zWindSpeed.value  r   r   Nrk   r   r   c                 *   t        |t              r|j                         }n+|)t        j                  j                  t               d      }|d}t        j                  j                  | j                  |      ||      }|j                  ||      S )Nr_   r`   r   r   r   r   r   s         r   r   zWindSpeed.l10n  r   r   r   )r~   r   r   r   r   r   r   r   r   rE   r   r   r   r   r]   r?   re   rf   r
   r   r   r   r   r   r   x  s     
J
&GXc]&,<E8E-()<;P- PE P &*48("9d"9 {*T19 	9
 9 
9r   r   %RelativeHumidityUnitRELATIVE_HUMIDITY_UNITSc            	           e Zd ZU dZeed<   dZee   ed<   e	Z
eee      ed<   d Zd Zdefd	Z	 	 	 ddej                   ez  d
z  dededefdZy
)r   z9Amount of relative humidity in the air. The unit is ``%``r   r   r   r   c                 d    | j                   | j                  vrt        d| j                          y r   r   rZ   s    r   r   zRelativeHumidity.__post_init__  r   r   c                 "    | j                         S rW   r   rZ   s    r   r]   zRelativeHumidity.__str__  r   r   r   c                     | j                   S rW   )r   rZ   s    r   r?   zRelativeHumidity.value  s    xxr   Nrk   r   r   c                 $   t        |t              r|j                         }n+|)t        j                  j                  t               d      }d}t        j                  j                  | j                         ||      }|j                  ||      S )Nr_   r`   r   r   r   r   )r[   rk   r   r   r   r   s         r   r   zRelativeHumidity.l10n  su     fk*]]_F^\\''(<(>C'HF--..tzz|FS^._W488r   )N{value}{unit}r   )r~   r   r   r   r   r   r   r   r   r   r   r   r   r]   r?   re   rf   r
   rE   r   r   r   r   r   r     s    C	J ,/D('
(.3JE8E./0J;u 
 59'"	9{*T19 9 	9
 
9r   r   )NNNENEENEEESESESSESSSWSWWSWWWNWNWNNWCompassPointCOMPASS_POINTS)   °PointCompassUnitCOMPASS_UNITSc                      e Zd ZU dZded<   dZeed<   eZe	e
e      ed<   dZe	e   ed<   	 eZe	e
e      ed	<   	 e ee      z  Ze	e   ed
<   	 d Zd ZdefdZedeez  defd       Z	 	 	 	 ddedej2                  ez  dz  dededef
dZy)r   u>   Class for converting compass points and azimuth values (360°)zfloat | int | CompassPointr   r   r   r   g     v@TURNPOINTSRANGEc                 P   t        | j                  t              rg| j                  | j                  vrt	        d| j                         | j                  j                  | j                        | j                  z  | _        | j                  | j                  z  | _        d| _        y )NzInvalid compass point: r   )	r   r   rE   r  rw   indexr  r   r   rZ   s    r   r   zCompass.__post_init__  su    dhh$xxt{{* #:488*!EFF{{((2TZZ?DH88dii'	r   c                 "    | j                         S rW   r   rZ   s    r   r]   zCompass.__str__  r   r   c                     |dk(  r5t        | j                  t              r| j                  | j                        S |dk(  r| j                  S t	        d|       )Nr   r   zunknown unit: )r   r   r   pointrw   )r[   r   s     r   r?   zCompass.value  sK    7?z$((E:::dhh''4<88O>$011r   azimuthr   c                     || j                   z  }|| j                  dz  z
  }t        || j                  z        }| j                  |   S )z.Returns the compass point to an azimuth value.   )r   r  intr  )rq   r  idxs      r   r  zCompass.point  sG     CHH$ CIIM)'SYY&'zz#r   Nrk   r   r   c                 t   t        |t              r|j                         }n+|)t        j                  j                  t               d      }|dk(  r$| j                  |      }|j                  |d      S t        j                  j                  | j                  |      ||      }|j                  ||      S )Nr_   r`   r   r#   r   r   )r   r
   rk   re   rf   rg   r2   r?   r   r   r   r   s         r   r   zCompass.l10n  s     fk*]]_F^\\''(<(>C'HF7?jj&G??r?::--..tzz$/?Wb.cW488r   )r   Nr   r   )r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   lenr  r   r]   r?   r   r  r  re   rf   r
   rE   r   r   r   r   r   r     s    H	%%D+*7E8E+&'7!D(5/!,:FHU<():!CK/E8E?/)2+ 2 ECK L   $48'"99 {*T19 	9
 9 
9r   r   ))	clear skypartly cloudycloudyfairfoglight rain and thunderlight rain showers and thunderlight rain showers
light rainrain and thunderrain showers and thunderrain showersrainheavy rain and thunderheavy rain showers and thunderheavy rain showers
heavy rainlight sleet and thunderlight sleet showers and thunderlight sleet showerslight sleetsleet and thundersleet showers and thundersleet showerssleetheavy sleet and thunderheavy sleet showers and thunderheavy sleet showersheavy sleetlight snow and thunderlight snow showers and thunderlight snow showers
light snowsnow and thundersnow showers and thundersnow showerssnowheavy snow and thunderheavy snow showers and thunderheavy snow showers
heavy snowr  01dr  03dr  04r  02dr  15r  30r  24dr  40dr  46r  22r  06dr  05dr  09r  11r  25dr  41dr  10r   31r!  26dr"  42dr#  47r$  23r%  20dr&  07dr'  12r(  32r)  27dr*  43dr+  48r,  33r-  28dr.  44dr/  49r0  1421d08d133429d45d50)r1  r2  r3  r4  r5  r6  r7  __main__)r3   z cached weather condition symbols=zproperties of )Ir   __all__typingr   trF   r   rX   urllib.parser   re   babel.numbersbabel.datesbabel.languagesr   msgspecr(   r   searx.cacher   r   searx.extended_typesr   searx.wikidata_unitsr   r   r   r   rB   r   rE   r2   r   Structr
   Literalr   r   r	   r   	TypeAliasget_argsr   Finalr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rA   r~   c_cachetitleprintr  statereportcfgr   
propertiesr   r   r   <module>r{     s=   ?
      #        3 - ?)- K$& - @v  c  F0 S4Z <KZ'..$ KZ\ ))=>iio .Qw~~ .Qb  !yy):; ;5?QZZ5P 177512 P=9'..$ =9@ II&ABakk B/9qzz,/Gl+, G'9w~~t '9T YY'PQq{{ Q2<!**]2K !''%./ K.9 .9b %&IIcN akk 2@J

K_@` ';!<= ` 9w~~  9F IIfakk  $/9qzz,/Gl+, G99]3Q[[ 3-7QZZ-Dqwwu[)* D>9gnn >9B yy+. ^	--U- d- E	-
 
4- d- %e- %- $- - - E- D- d-  %e!-" %#-$ $%-( t)-* &u+-, 5--. 4/-0 1-2  3-4 U5-6 T7-8 t9-: &u;-< 5=-> 4?-B dC-D %eE-F %G-H $I-J K-L !&"&+Y- \	 z QZZ,-  Q  $%F.E	%L	#E

	&,,.


!"	GVZZ__-.E	%L	#E

	#f
 ! r   