
    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Z	 d dlZ G d de
      ZddZd	dZedk(  rd dlZ ej                           yy# e$ r  ej                  d       dZY Jw xY w)
    Nz1Pandas library not installed, dataframes disabledc                       e Zd Zy)NoResultExceptionN)__name__
__module____qualname__     \/mounts/lovelace/software/anaconda3/envs/py312/lib/python3.12/site-packages/pytaxize/taxo.pyr   r      s    r	   r   c                 (   d}t        j                  |      }|j                          |j                         d   }| rUg }t	        t        |            D ]!  }|j                  ||   d   ||   d   g       # t        j                  |ddg      }|S |S )a7  
    Get data sources for Taxosaurus. Retrieve data sources used in
    Global Names Index, see http://taxosaurus.org/ for information.

    Usage::
    
        # all data sources
        import pytaxize
        pytaxize.taxo_datasources()

        # Output a dict
        pytaxize.taxo_datasources(False)
    zhttp://taxosaurus.org/sources/sourcessourceIdnameid)columns)	requestsgetraise_for_statusjsonrangelenappendpd	DataFrame)as_dataframeurloutdataidfs         r
   taxo_datasourcesr       s     +C
,,s
C
((*Y
Cs3x 	>AKKQ
+SVF^<=	>\\$v7	
r	   c           	      :   d}i }t        | t              r-t        |       dkD  r|dk(  rd}ndj                  |       } | |d<   n| |d<   |dk(  r$t	        j
                  ||      }|j                  }n||d<   ||d	<   | j                  j                  d
k7  r$t	        j                  ||      }|j                  }nt        dd      5 }| D ]  }	|j                  |	dz           	 ddd       j                          t	        j                  ||dt        dd      i      }|j                  }t        j                  d       t	        j
                  |      }|j                          |j!                         }
|
d   dk(  rSt#        j$                  d       t	        j
                  |      }|j                          |j!                         }
|
d   dk(  rSg }|
d   D ]  }|j'                  d|v r|d   ng         |g gk(  rt)        j*                  d       |S # 1 sw Y   2xY w)a  
    Uses Taxosaurus to resolve scientific names

    :param query: List of taxonomic names
    :param source: (optional) Source to pull from
    :param code: (optional) the abbreviation for one of the nomenclature codes
        (ICZN: International Code of Zoological Nomenclature; ICN: International
        Code of Nomenclature for algae, fungi, and plants; ICNB: International
        Code of Nomenclature of Bacteria)
    :param http: (optional) The HTTP method to use, one of "get" or "post".
        Default="get"
    
    Usage::
    
        import pytaxize
        pytaxize.taxo_resolve(query='Helianthus annus')
        pytaxize.gnr_resolve(['Helianthus annus','Poa annua'])
    zhttp://taxosaurus.org/submiti,  r   post
query)paramssourcecodelistznames_list.txtwNfilerb)r%   filesstatusfound
   namesmatchesz No matching results to the query)
isinstancer(   r   joinr   r   r   	__class__r   r"   openwritecloseosremover   r   timesleepr   sysexit)r$   r&   r'   httpr   payloadr   	token_urlfr   result_jsonr   each_results                r
   taxo_resolverD   /   s   & )CG%u:DIIe$E$GG u}ll3w/GG	"??##v---G4CI&, )! )DGGD4K()) GGI--GFD9I44P+QC III&'
,,y
!C((*K
h
7
*

2ll9%hhj	 h
7
*
 D"7+ Pi;.FK	*BOPt|34K1) )s   HH__main__)F)NNr   )r<   warningsr   r   r:   r8   pandasr   ImportErrorwarn	Exceptionr   r    rD   r   doctesttestmodr   r	   r
   <module>rM      s{    
     			 	8@F zGOO Q  HMMEF	Bs   A A)(A)