o
    .j                     @   s   d Z ddlZddlZddlZddlZddlZejddZejddZ	dZ
g dZg dZd	d
 Zdd Zdd Zdd ZedkrGe  dS dS )zEMorning briefing - reads APPLE_EMAIL and APPLE_APP_PASSWORD from env.    NAPPLE_EMAIL APPLE_APP_PASSWORDzhttps://caldav.icloud.com)z4Your smile is literally the best part of my morning.zEI love how you always know exactly what to say to make things better.z:You're the kind of person who makes everyone feel at home.z+The world is brighter because you're in it.zGYou have this incredible way of turning ordinary moments into memories.z4I'm constantly amazed by your strength and kindness.z You're my favorite notification.zYour laugh is my favorite song.z0You make 'home' feel like a person, not a place.zQI don't think you realize how incredible you are, but I hope I remind you enough.zQYou're the plot twist I never saw coming and now can't imagine the story without.zDYou carry yourself with a grace that's both effortless and powerful.z?Your curiosity about the world makes me see it differently too.z5You're the reason I believe in good things happening.z@Every day with you feels like discovering something new to love.z3You have a heart that somehow keeps getting bigger.z$I admire how you never stop growing.zYou're my calm in the chaos.zBThe way you care about people is a gift to everyone who knows you.z)You make even Mondays feel like weekends.)z%https://feeds.bbci.co.uk/news/rss.xmlz0https://feeds.bbci.co.uk/news/technology/rss.xmlz#https://rss.cnn.com/rss/edition.rssz/https://feeds.arstechnica.com/arstechnica/indexc                  C   s`  t rtsdS ztjtt td} |  }| }|sW dS tj	 }|tj
dd }g }|D ]]}z?|j||ddd}|D ]1}|jj}	tt|	dd	}
t|	d
d }d}|ra|j}t|tjra|d}|d| d|
  q;W q- ty } ztd| tjd W Y d }~q-d }~ww |sW dS dt|W S  ty } zd| dW  Y d }~S d }~ww )Nz*Calendar not configured.*)urlusernamepasswordz*No calendars found.*   )daysT)startendeventexpandsummaryzNo titledtstartzAll dayz%H:%M   • z: zCalendar error: )filez *No events scheduled for today.*
z*Couldn't fetch calendar: *)r   r   caldav	DAVClient
CALDAV_URL	principal	calendarsdatetimedatetoday	timedeltasearchvobject_instanceveventstrgetattrvalue
isinstancestrftimeappend	Exceptionprintsysstderrjoinsorted)clientr   r   r   tomorrow
all_eventscalendareventsr   r   r   r   time_strste r4   1/home/thesage/.hermes/scripts/morning_briefing.pyget_today_events'   sJ   


r6   c               	   C   s   g } t D ]1}z&t|}|jd d D ]}|dd }|r*t|dkr*| | qW q ty5   Y qw | s:dS t	
| tdt| }ddd |D S )	N   titler   
   z*Couldn't fetch news today.*r   c                 s   s    | ]}d | V  qdS )r   Nr4   ).0hr4   r4   r5   	<genexpr>W   s    z%get_news_headlines.<locals>.<genexpr>)
NEWS_FEEDS
feedparserparseentriesgetstriplenr%   r&   randomsampleminr*   )	headlinesfeed_urlfeedentryr8   selectedr4   r4   r5   get_news_headlinesI   s"   

rL   c                   C   s
   t tS )N)rD   choiceCOMPLIMENTS_POOLr4   r4   r4   r5   get_daily_complimentY   s   
rO   c               	   C   sL   t  } t }t }tj d}d| d|  d| d| d	}t| d S )Nz	%A, %B %dzGood morning, Sage!

Today is u   .

📅 Your day:
u   

🌍 Today's headlines:
u   

💝 For her:
z

Have a great day!)r6   rL   rO   r   r   r   r$   r'   )r0   news
compliment	today_strmessager4   r4   r5   main\   s   rT   __main__)__doc__r   r   rD   r>   osenvironrA   r   r   r   rN   r=   r6   rL   rO   rT   __name__r4   r4   r4   r5   <module>   s   ("
