
    EPc                         d Z ddlZddlZddlmZ ddlZddlmZmZ ddlm	Z	 ddl
mZ ddlmZ d Z G d	 d
e          ZdS )zV
Access Bioicons.

Downloads the database to cache and uses it locally for searching.
    N)datetime)CacheControlCacheControlAdapter)	FileCache)ExpiresAfter)RemoteSourcec              #   x   K   |D ]4}|                                  |d                                          v r|V  5d S )Nname)lower)querydbitems      @/usr/share/inkscape/extensions/other/clipart/sources/bioicons.pylocal_searchr   $   sG        ;;==DL..0000JJJ
F    c                   *    e Zd Zd ZdZdZdZd Zd ZdS )Bioiconszsources/bioicons.svgz%https://bioicons.com/icons/icons.jsonzhttps://bioicons.com/icons/c           	         t          j                    | _        || _        | j                            dt	          t          |          t          d                               	 t          j        | j                  }n# t          $ r d }Y nw xY wt          j                            | j        d          | _        t          j                            | j                  sd}n$t          j                            | j                  }|Tt!          j        |j        d         d                                          }||k     r|                     | j                   d S d S d S )	Nzhttps://   )days)cache	heuristicz
icons.jsonr   zLast-Modifiedz%a, %d %b %Y %H:%M:%S GMT)requestssession	cache_dirmountr   r   r   headdb_url	Exceptionospathjoin_jsonisfilegetmtimer   strptimeheaders	timestampto_local_file)selfr   responselast_modifiedlast_updates        r   __init__zBioicons.__init__1   sY   '))"	**&A...  	
 	
 	
	}T[11HH 	 	 	HHH	 W\\$.,??
w~~dj)) 	9MMG,,TZ88M"+ 13N ikk  {**""4;/////  
 +*s   &B   BBc              #     K   g }t           j                            | j                  rQt	          | j        d          5 }t          j        |          }d d d            n# 1 swxY w Y   t          ||          }|D ]}|d         |d         |d         d d|d         | j         |d          d|d          d|d          d|d          d	| j         |d          d|d          d|d          d|d          d	|d         d		V  d S )
Nrr
   categoryr   authorlicense/z.svg)	idr
   summarycreated
popularityr2   	thumbnailfiler3   )	r    r!   r$   r#   openjsonloadr   icon_url)r*   r   resultsfr   r   s         r   searchzBioicons.searchO   s     7>>$*%% 	.dj#&& "!Yq\\" " " " " " " " " " " " " " ""5"--G 	 	D6lV
+x. $wtIwwjAQwwTXYaTbwweijpeqwww=r$y/rrD<LrrtT\~rr`dek`lrrr	?
 
 
 
 
 
	 	s   AA#&A#N)	__name__
__module____qualname__r
   iconr   r>   r.   rA    r   r   r   r   +   sF        D!D4F,H0 0 0<    r   r   )__doc__r<   r   r   r    cachecontrolr   r   cachecontrol.caches.file_cacher   cachecontrol.heuristicsr   import_sourcesr   r   r   rF   r   r   <module>rL      s   "          				 ; : : : : : : : 4 4 4 4 4 4 0 0 0 0 0 0 ' ' ' ' ' '  6 6 6 6 6| 6 6 6 6 6r   