U
    [Mh                     @   s*   d dl Z d dlZdd Zedkr&e  dS )    Nc                  C   s  t d ztjddd} | jdkrz|  }t d t d|dd	  t d
|dd	  t d|dd	  tjddd}|jdkrh| }t d | D ]$\}}t d| d|dd	  qd }| D ]}d| kr|} qq|r@t d|  ddlm}m	}m
}	 ||j}
|
|	dd }tjd| d| |
 dddd}|jdkr.| }t dt| d  t|d d D ]j\}}|d!i }|d"d	}|d#d$d d% }|d&d}t d'|d(  d)| d*| d+|d,d-	 qt|dkr$t d. t d/ nt d0 nt d1|j  n&t d2 | D ]}t d|  qPnt d3|j  nt d4| j  W nR tk
r } z2t d5|  t d6 t d7 t d8 t d9 W 5 d }~X Y nX d S ):Nu)   🔄 Testing ActivityWatch connection...
z http://localhost:5600/api/0/info   )timeout   u   ✅ ActivityWatch is running!z   Version: versionZUnknownz   Hostname: Zhostnamez   Device ID: Z	device_idz#http://localhost:5600/api/0/buckets
   u   
📊 Available buckets:z   - z: typeZwindowu   
✅ Found window bucket: r   )datetimetimezone	timedelta   )Zhoursz$http://localhost:5600/api/0/buckets/z/events)startendlimit   )paramsr   u   
📥 Found z recent events:dataapptitlezNo title2   durationz      z. z | z... | z.1fsu)   
🎉 ActivityWatch is working perfectly!uL   ✅ You can now start your backend and it will sync this data automatically.uK   
⚠️  No recent events found. Make sure you've been using your computer.u   ❌ Could not get events: u/   
❌ No window bucket found. Available buckets:u   ❌ Could not get buckets: u(   ❌ ActivityWatch responded with error: u%   ❌ Cannot connect to ActivityWatch: u   
💡 To fix this:z6   1. Make sure ActivityWatch is installed and runningz:   2. Check if http://localhost:5600 opens in your browserz=   3. If ActivityWatch is on a different port, update the URL)printrequestsgetZstatus_codeZjsonitemskeyslowerr   r	   r
   ZnowZutcZ	isoformatlen	enumerate	Exception)ZresponseinfoZbuckets_responseZbucketsZbucket_nameZbucket_infoZwindow_bucketr   r	   r
   Zend_timeZ
start_timeZevents_responseZeventsiZeventr   r   r   r   namee r%   ./simple_test.pytest_simple   st    

,

r'   __main__)r   osr'   __name__r%   r%   r%   r&   <module>   s   N