
    Mg                     t    S r SSKJr  SSKJr  SSKrSSKJrJr  \" SS9\" S5       " S	 S
5      5       5       rg)zu
Calculates the haversine distance (distance along Earths surface) 
between the centroids of two supplied countries.
    )	haversine)ForeN)pluginrequireT)networkdistancec                   @    \ rS rSr " S S5      rS rSSS\4S jrS	rg
)	Distances   c                   .    \ rS rSrS rS\4S jrS rSrg)Distances.Location   c                     U R                   $ Ncountry_name)selfs    >/Users/admin/workspace/ai/Jarvis/jarviscli/plugins/distance.py__str__Distances.Location.__str__   s    $$$    r   c                     Xl         g r   r   )r   r   s     r   __init__Distances.Location.__init__   s     ,r   c                    SU R                    3n[        R                  " U5      nUR                  S:w  a  SU l        g UR                  5       S   nUR                  S5      U l        UR                  S5      R                  S5      U l         g )Nz$https://restcountries.com/v3.1/name/   Fr   latlngnamecommon)r   requestsgetstatus_codecoordinatesjson)r   urlpayloadresponses       r   geocodeDistances.Location.geocode   sx    89J9J8KLCll3'G""c)#(  #<<>!,#+<<#9 $,LL$8$<$<X$F!r   )r#   r   N)	__name__
__module____qualname____firstlineno__r   strr   r(   __static_attributes__ r   r   Locationr      s    	%	- 	-
	Gr   r1   c                     [        SU S35      nU R                  U5      nUR                  5         UR                  (       d  UR	                  SU S35        U$ )Nz
Enter the z
 country: zCountry z not recognized, try again!)inputr1   r(   r#   say)r   orderjarvisscountry_strcountrys         r   create_locationDistances.create_location$   sQ    jz:;--,""JJ'*EFGr   r6   	JarvisAPIr7   c           	         U R                  SX5      nU R                  SX5      nUR                  (       aO  UR                  (       a=  [        UR                  UR                  5      nUR                  SU SU SUS S35        g g g )NfirstsecondzThe distance between z and z is z.2fz km)r:   r#   r   r4   )r   r6   r7   	country_1	country_2haversine_distances         r   __call__Distances.__call__-   s    ((&<	((6=	  Y%:%:!*9+@+@)BWBW!XJJ.ykykN`adMeehij &; r   r0   N)	r*   r+   r,   r-   r1   r:   r.   rC   r/   r0   r   r   r
   r
      s)    G G&k{ ks kr   r
   )__doc__r   coloramar   r    r   r   r
   r0   r   r   <module>rG      sF   
     " 	
$k $k  $kr   