
    H&h                         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Z G d de	      Z
d Z	 	 d	dZ	 	 d	dZedk(  rd dlZ ej                           yy)
    N)Refactorc                       e Zd Zy)NoResultExceptionN)__name__
__module____qualname__     [/mounts/lovelace/software/anaconda3/envs/py312/lib/python3.12/site-packages/pytaxize/gnr.pyr   r   	   s    r
   r   c                  B    d} t        | i d      j                         }|S )a  
    Get data sources for the Global Names Resolver.

    Retrieve data sources used in Global Names Index, see
       http://gni.globalnames.org/ for information.

    Usage::

        # all data sources
        import pytaxize
        pytaxize.gnr_datasources()

        # give me the id for EOL
        out = pytaxize.gnr_datasources()
        [d for d in out if d['title'] in 'EOL'][0]['id']
    z2https://resolver.globalnames.org/data_sources.jsongetpayloadrequest)r   json)urldatas     r   gnr_datasourcesr      s%    " ?CCU388:DKr
   c	                 J   | j                   j                  dk7  rt        | ||||||||	      S d}	t        dt	        |       |	      D 
cg c]
  }
| |
|
|	z     }}
g }|D ]$  }|j                  t        |||||||||	             & |g gk(  rt        j                  d       |S c c}
w )a  
    Uses the Global Names Resolver to resolve scientific names

    :param names: List of taxonomic names
    :param source: Source to pull from, one of x, y, z
    :param format: One of json or xml
    :param resolve_once: Logical, true or false
    :param with_context: Return context with taxonomic names
    :param best_match_only: Logical, if true (default) return the best match only
    :param header_only: Return header only, logical
    :param preferred_data_sources: Return only preferred data sources.
    :param http: The HTTP method to use, one of "get" or "post". Default="get"

    Usage::

        import pytaxize
        pytaxize.gnr_resolve('Helianthus annus')
        pytaxize.gnr_resolve(['Helianthus annus','Poa annua'])
    listi  r   z No matching results to the query)	__class__r   _gnr_resolverangelenextendsysexit)namessourceformatresolve_oncewith_contextbest_match_onlyheader_onlypreferred_data_sourceshttpmaxlenxnames_sublistsr   sublists                 r   gnr_resolver+   !   s    * 6)E66</;"D* 	* F16q#e*f1MNAeAah'NNND! OL&&,/;0FN 	OO t|34K Os   B c	                 V   d}	|||||||d}
| j                   j                  dk(  r-t        |       dkD  r|dk(  rd}ndj                  |       } | |
d<   n| |
d<   |dk(  rt	        |	|
d	      j                         }n| j                   j                  dk7  rt	        |	|
d	      j                         }nt        d
d      5 }| D ]  }|j                  |dz           	 d d d        j                          t	        |	|
d	      j                  dt        d
d      i      }|d   dk(  r?|d   }t        j                  d       t	        |i d      j                         }|d   dk(  r?t        j                  d
       g }|d   D ]  }|j                  d|v r|d   ng         |S # 1 sw Y   xY w)Nz/https://resolver.globalnames.org/name_resolvers)data_source_idsr    r!   r"   r#   r$   r%   r   i,  r   post|r   )r   znames_list.txtw
filerb)filesstatusworkingr   
   r   r   results)r   r   r   joinr   r   openwriteclosetimesleeposremoveappend)r   r   r    r!   r"   r#   r$   r%   r&   r   r   result_jsonfname
result_urlr   each_results                    r   r   r   G   s    <C"(F ,l#2;*@BG 6)u:DHHUOE$GG u}sGU;@@B??##v-!#w?DDF;&, '! 'DGGDI&'' GGI"3@EEvW[\lnrWsNtEuKh'94(/


2&z2eLQQS h'94
 II&'D"6* Pi;.FK	*BOP K!' 's   <FF(__main__)	zHomo sapiensNr   falserH   rH   rH   rH   r   )r   requestspandaspdr   r=   pytaxize.refactorr   r?   	Exceptionr   r   r+   r   r   doctesttestmodr	   r
   r   <module>rP      si    
     & 			 	* PWmr$L QXmr&P zGOO r
   