
    H&h                     B    d dl Z d dlZd dlZd dlmZ d dlmZ ddZd Zy)    N)Refactor)Idsc                    t        |       }|j                         }t        |      dkD  r|D cg c]  }t        |d   fi | }}nt        |d   d   fi |}t	        | t
              r| g} t        t        | |            S c c}w )aK  
  Get common names from scientific names.

  :param: sci (str) One or more scientific names or partial names. optional
  :param: id (str/int) One or more taxonomic identifiers. optional
  :param: db (str) Data source, default: "ncbi". NCBI only supported right
  now, other sources to come.
  :param: **kwargs Curl options passed on to `requests.get`

  :return: dict, keys are supplied scientific names, and values
  are common names

  Remember to set your Entrez API key as `ENTREZ_KEY`

  Usage::
    
    import pytaxize

    pytaxize.sci2comm(sci='Helianthus annuus')
    pytaxize.sci2comm(sci='Puma concolor')
    pytaxize.sci2comm(sci=['Helianthus annuus', 'Poa annua'])
    pytaxize.sci2comm('Gadus morhua')
    pytaxize.sci2comm('Pomatomus saltatrix')
    pytaxize.sci2comm('Loxodonta africana')

    pytaxize.sci2comm('foo bar')
     idr   )r   ncbilen_ncbi_common_names
isinstancestrdictzip)scir   dbkwargsxoutwress           `/mounts/lovelace/software/anaconda3/envs/py312/lib/python3.12/site-packages/pytaxize/sci2comm.pysci2commr      s    8 	CA
&&(C
3x!|>AB!!D'4V4BB Q88#seC Cs   Bc                    t         j                  j                  d      }|t        d      d| |d}d} t	        ||d      j
                  di |}|j                  d      }|D cg c]  }|j                   c}S c c}w )	N
ENTREZ_KEYzENTREZ_KEY is not definedtaxonomy)r   IDapi_keyz9https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgigetz,//TaxaSet/Taxon/OtherNames/GenbankCommonName )osenvironr   	Exceptionr   xmlxpathtext)r   r   keyqueryurlr   zr   s           r   r
   r
   /   s{    
**..
&C
{344Q37E
EC
)(3u
%
)
)
3F
3C		@AAqAFFs   'A=)NNr   )	r   requestsjsonpytaxize.refactorr   pytaxize.idsr   r   r
   r       r   <module>r.      s    	   & $N	r-   