U
    ¤�©j¤  ã                   @   sr   d Z ddlZddlZddlZddlmZ ddlmZmZ dd„ Zdd„ Z	d	d
„ Z
dd„ Zdd
gZedkrneƒ  dS )z=utility program that allows user to preview calendar's eventsé    N)Údatetime)ÚCalendarÚ__version__c                 C   s4   |   d¡d }|  d¡d }|s$dS |› d|› d�S )z¢Retrieve the e-mail and the name from an address.

    :arg an address object, e.g. mailto:test@test.test

    :returns str: The name and the e-mail address.
    ú:éÿÿÿÿú@r   Ú z <ú>)Úsplit)ÚaddressÚemailÚname© r   ú1/tmp/pip-unpacked-wheel-g40nyxg1/icalendar/cli.pyÚ_format_name   s
    r   c                 C   s*   t | tƒr| g} d tdd„ tt| ƒƒ¡S )zœFormat the list of attendees.

    :arg any attendees: Either a list, a string or a vCalAddress object.

    :returns str: Formatted list of attendees.
    Ú
c                 S   s   |   t| ƒd ¡S ©Né   ©ÚrjustÚlen©Úsr   r   r   Ú<lambda>#   ó    z#_format_attendees.<locals>.<lambda>)Ú
isinstanceÚstrÚjoinÚmapr   )Ú	attendeesr   r   r   Ú_format_attendees   s    
r    c           
      C   s0  | j ddd�}t| j ddd�ƒ}t| j dg d�ƒ}| j ddd�}|   dd¡}|   dd¡ d	¡}d	 td
d„ |ƒ¡}|  d¡}d| krž| jd||  d¡ d�}n| jd|d�}| jd|| d�}	t|tƒrÐ| 	¡ }| 
d¡}t|tƒrì| 	¡ }| 
d¡}d|› d|› d|› d|› d|› d|	› d|› d|› d|› �S )zcMake a human readable summary of an iCalendar file.

    :returns str: Human readable summary.
    Úsummaryr   )ÚdefaultÚ	organizerZattendeeÚlocationÚcommentÚdescriptionr   c                 S   s   |   t| ƒd ¡S r   r   r   r   r   r   r   1   r   zview.<locals>.<lambda>ZdtstartÚdurationZdtendz%cz    Organizer: z
    Attendees:
z
    Summary    : z
    Starts     : z
    End        : z
    Duration   : z
    Location   : z
    Comment    : z
    Description:
)Úgetr   r    r
   r   r   Údecodedr   r   Ú
astimezoneÚstrftime)
Úeventr!   r#   r   r$   r%   r&   ÚstartÚendr'   r   r   r   Úview&   sF    




þýüûúùø
ör/   c               
   C   sº   t jtd�} | jddtjd� | jddt  d¡tjdd	� | jd
dd| j	› dt
› �d� |  ¡ }|jD ]N}t|dd��8}t | ¡ ¡}| d¡D ]}|j t|ƒd ¡ q�W 5 Q R X qfd S )N)r&   Úcalendar_filesú+)ÚnargsÚtypez--outputz-oÚwzoutput file)r3   r"   Úhelpz-vz	--versionÚversionz	 version )Úactionr6   z	utf-8-sig)ÚencodingZveventz

)ÚargparseÚArgumentParserÚ__doc__Úadd_argumentÚpathlibÚPathÚFileTypeÚsysÚstdoutÚprogr   Ú
parse_argsr0   Úopenr   Z	from_icalÚreadÚwalkÚoutputÚwriter/   )ÚparserÚargvZcalendar_fileÚfÚcalendarr,   r   r   r   ÚmainM   s*    ûü
rM   Ú__main__)r;   r@   r=   r9   r   Z	icalendarr   r   r   r    r/   rM   Ú__all__Ú__name__r   r   r   r   Ú<module>   s   '