Dre4m Shell
Server IP : 85.214.239.14  /  Your IP : 18.118.10.75
Web Server : Apache/2.4.62 (Debian)
System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.18
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /proc/3/cwd/proc/3/cwd/srv/modoboa/env/lib64/python3.5/site-packages/icalendar/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /proc/3/cwd/proc/3/cwd/srv/modoboa/env/lib64/python3.5/site-packages/icalendar/cli.py
# -*- coding: utf-8 -*-
"""iCalendar utility"""
from __future__ import unicode_literals

import argparse
import sys
from datetime import datetime

from . import Calendar, __version__


_template = """Organiser: {organiser}
Attendees:
  {attendees}
Summary: {summary}
When: {time_from}-{time_to}
Location: {location}
Comment: {comment}
Description:

{description}

"""


def _format_name(address):
    """Retrieve the e-mail and optionally the name from an address.

    :arg vCalAddress address: An address object.

    :returns str: The name and optionally the e-mail address.
    """
    if not address:
        return ''

    email = address.title().split(':')[1]
    if 'cn' in address.params:
        return '{} <{}>'.format(address.params['cn'], email)

    return email


def _format_attendees(attendees):
    """Format the list of attendees.

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

    :returns str: Formatted list of attendees.
    """
    if type(attendees) == list:
        return '\n  '.join(map(_format_name, attendees))
    return _format_name(attendees)


def view(input_handle, output_handle):
    """Make a human readable summary of an iCalendar file.

    :arg stream handle: Open readable handle to an iCalendar file.

    :returns str: Human readable summary.
    """
    cal = Calendar.from_ical(input_handle.read())

    for event in cal.walk('vevent'):
        output_handle.write(_template.format(
            organiser=_format_name(event.get('organizer', '')),
            attendees=_format_attendees(event.get('attendee')),
            summary=event.get('summary', ''),
            time_from=datetime.strftime(
                event.get('dtstart').dt, '%a %d %b %Y %H:%M'),
            time_to=datetime.strftime(event.get('dtend').dt, '%H:%M'),
            location=event.get('location', ''),
            comment=event.get('comment', ''),
            description=event.get('description', '')).encode('utf-8'))


def main():
    """Main entry point."""
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description=__doc__)
    parser.add_argument(
        '-v', '--version', action='version',
        version='{} version {}'.format(parser.prog, __version__))

    # This seems a bit of an overkill now, but we will probably add more
    # functionality later, e.g., iCalendar to JSON / YAML and vice versa.
    subparsers = parser.add_subparsers(dest='subcommand')

    subparser = subparsers.add_parser(
        'view', description=view.__doc__.split('\n\n')[0])
    subparser.add_argument(
        'input_handle', metavar='INPUT', type=argparse.FileType('r'),
        help='iCalendar file')
    subparser.add_argument(
        '-o', dest='output_handle', metavar='OUTPUT',
        type=argparse.FileType('w'), default=sys.stdout,
        help='output file (default=<stdout>)')
    subparser.set_defaults(func=view)

    args = parser.parse_args()

    try:
        args.func(**{k: v for k, v in vars(args).items()
            if k not in ('func', 'subcommand')})
    except ValueError as error:
        parser.error(error)


if __name__ == '__main__':
    main()

Anon7 - 2022
AnonSec Team