
    h
                        S r SSKrSSKrSSKJr   " S S5      r\S:X  a  \" S5        \" 5       r\" S5        \R                  S	5      r	\	S
   (       a  \" S5        \" S\	S    35        O\" S5        \R                  5       r\" S5        \" S\S    35        \" S\S    35        \" S5        \" S5        \" S5        \" S5        \" S5        \" S5        gg)z7
Web Integration - Eden can interact with the internet
    N)datetimec                   6    \ rS rSrS rS	S jrS rS rS rSr	g)
WebIntegration   c                 F    [         R                  " 5       U l        / U l        g )N)requestsSessionsessionrequest_history)selfs    @/home/james-whalen/eden-agi-project/core/apis/web_integration.py__init__WebIntegration.__init__	   s    '')!    c                     U R                   R                  " X!40 UD6nSUR                  UU[        R                  " 5       R                  5       S.n UR                  5       US'   U R                  R                  U5        U$ !   UR                  SS US'    N3= f! [         a;  nS[        U5      U[        R                  " 5       R                  5       S.s SnA$ SnAff = f)zMake HTTP requestT)successstatus_codeurlmethod	timestampdataNi  F)r   errorr   r   )r
   requestr   r   now	isoformatjsontextr   append	Exceptionstr)r   r   r   kwargsresponseresultes          r   	fetch_urlWebIntegration.fetch_url   s    	||++FB6BH  '33 %\\^557F6!)v   ''/M	6!)u!5v
  	 Q%\\^557	 	s6   AB B &B BB 
C!&0CC!C!c                 "    U R                  USS9$ )zFetch and parse JSON APIGET)r   r%   )r   r   s     r   
fetch_jsonWebIntegration.fetch_json+   s    ~~c%~00r   c                 $    U R                  USUS9$ )zPOST data to APIPOST)r   r   r)   )r   r   r   s      r   	post_dataWebIntegration.post_data/   s    ~~c&t~<<r   c                     [        U R                  5      n[        S U R                   5       5      nUUX-
  US:  a  X!-  S.$ SS.$ )zStatistics on API usagec              3   <   #    U  H  oS    (       d  M  Sv   M     g7f)r      N ).0rs     r   	<genexpr>3WebIntegration.get_request_stats.<locals>.<genexpr>6   s     I$8qiL$8s   	r   )total_requests
successfulfailedsuccess_rate)lenr   sum)r   totalr9   s      r   get_request_stats WebIntegration.get_request_stats3   s]    D(()ID$8$8II
 $$(27!)J.	
 	
 BC	
 	
r   )r   r
   N)r(   )
__name__
__module____qualname____firstlineno__r   r%   r*   r.   r?   __static_attributes__r3   r   r   r   r      s    "<1=

r   r   __main__zWEB INTEGRATION TESTu!   
🌐 Testing web connectivity...zhttps://api.github.com/zenr   u$      ✅ Successfully connected to webz   Status: r   u+      ⚠️  Network test (may need internet)u   
📊 Request Stats:z
   Total: r8   z   Successful: r9   u   
🌐 Eden can now:z   - Make HTTP requestsz   - Fetch JSON APIsz   - POST data to servicesz   - Track web interactionsu    
✅ WEB INTEGRATION OPERATIONAL)__doc__r   r   r   r   rA   printwebr*   r#   r?   statsr3   r   r   <module>rK      s     5
 5
n z	
 !

C 

./^^89Fi46F=1234;=!!#E	!#	Ju-./
01	OE,/0
12	
 !	
#$	
 !	
&'	
'(	
-.5 r   