Exemplo n.º 1
0
def eventListFunction(args=None):
    date = {"dateStart": None, "dateEnd": None}
    calendar = gc.checkCalendar("eventsCalendar", "summary")

    if not calendar:
        newCalendar = {}
        newCalendar["summary"] = "eventsCalendar"

        calendar = gc.createCalendar(newCalendar)
        return None

    if args is None or args == '' or args == []:
        eventList = gc.getEvents(calendar['id'])
    else:
        if (''.join(args).find("|") != -1):
            date["dateStart"] = translateStringToDatetime(
                date=''.join(args).split("|")[0])["dateStart"]
            date["dateEnd"] = translateStringToDatetime(
                date=''.join(args).split("|")[1])["dateStart"]
        else:
            date = translateStringToDatetime(date=''.join(args))

        if (date['dateStart'] == None or date['dateEnd'] == None):
            return 1

        eventList = gc.getEvents(
            calendar['id'],
            timezone('Europe/Madrid').localize(date["dateStart"]).astimezone(
                timezone('UTC')).strftime("%Y-%m-%dT%XZ"),
            timezone('Europe/Madrid').localize(date["dateEnd"]).astimezone(
                timezone('UTC')).strftime("%Y-%m-%dT%XZ"))
    return eventList
Exemplo n.º 2
0
def birthdayAddFunction(args, summary):
    calendar = gc.checkCalendar("birthdaysCalendar", "summary")

    if not calendar:
        newCalendar = {}
        newCalendar["summary"] = "birthdaysCalendar"

        calendar = gc.createCalendar(newCalendar)

    if args is None or args == '' or args == []:
        return None
    else:
        date = translateStringToDatetime(date=''.join(args))
        if (date['dateStart'] == None or date['dateEnd'] == None):
            return 1
        if ((datetime.now().year - date['dateStart'].year) < 0
                or (datetime.now().year - date['dateStart'].year) > 120 or
            (date['dateEnd'] - date['dateStart']).total_seconds() != 86400):
            return 2

        event = {
            'summary': summary + '|' + date['dateStart'].strftime("%Y"),
            'start': {
                'date': date['dateStart'].strftime("%Y-%m-%d"),
                'timeZone': 'Europe/Madrid',
            },
            'end': {
                'date': date['dateEnd'].strftime("%Y-%m-%d"),
                'timeZone': 'Europe/Madrid',
            },
            'recurrence': ['RRULE:FREQ=YEARLY;'],
        }

        return gc.createEvent(event=event, calendarId=calendar['id'])
Exemplo n.º 3
0
def birthdayListFunction(args=None):
    calendar = gc.checkCalendar("birthdaysCalendar", "summary")

    if not calendar:
        newCalendar = {}
        newCalendar["summary"] = "birthdaysCalendar"

        calendar = gc.createCalendar(newCalendar)
        return None

    if args is None or args == '' or args == []:
        eventList = gc.getEvents(calendar['id'])
    else:
        if (''.join(args).find("|") != -1):
            date["dateStart"] = translateStringToDatetime(
                date=''.join(args).split("|")[0])["dateStart"]
            date["dateEnd"] = translateStringToDatetime(
                date=''.join(args).split("|")[1])["dateStart"]
        else:
            date = translateStringToDatetime(date=''.join(args))

        if (date['dateStart'] == None or date['dateEnd'] == None):
            return 1

        eventList = gc.getEvents(calendar['id'],
                                 date["dateStart"].strftime("%Y-%m-%dT%XZ"),
                                 date["dateEnd"].strftime("%Y-%m-%dT%XZ"))
    return eventList
Exemplo n.º 4
0
def eventInfoFunction(eventId):
    calendar = gc.checkCalendar("eventsCalendar", "summary")

    if not calendar:
        newCalendar = {}
        newCalendar["summary"] = "eventsCalendar"

        calendar = gc.createCalendar(newCalendar)
        return None

    return gc.checkEvent(eventId, calendar['id'])
Exemplo n.º 5
0
def eventCheckFunction(event_id):
    calendar = gc.checkCalendar("eventsCalendar", "summary")

    if not calendar:
        newCalendar = {}
        newCalendar["summary"] = "eventsCalendar"

        calendar = gc.createCalendar(newCalendar)
        return False

    return gc.checkEvent(eventId=event_id, calendarId=calendar['id'])
Exemplo n.º 6
0
def eventRemoveFunction(args):
    calendar = gc.checkCalendar("eventsCalendar", "summary")

    if not calendar:
        newCalendar = {}
        newCalendar["summary"] = "eventsCalendar"

        calendar = gc.createCalendar(newCalendar)
        return None

    if args is None or args == '' or args == []:
        return 1
    else:
        gc.removeEvent(''.join(args), calendar['id'])
        return 200
Exemplo n.º 7
0
def birthdayRemoveFunction(args):
    calendar = gc.checkCalendar("birthdaysCalendar", "summary")

    if not calendar:
        newCalendar = {}
        newCalendar["summary"] = "birthdaysCalendar"

        calendar = gc.createCalendar(newCalendar)
        return None

    if args is None or args == '' or args == []:
        return 1
    else:
        eventList = gc.getEvents(calendar['id'])
        for event in eventList:
            if ''.join(args) in event['summary']:
                gc.removeEvent(event['id'].split("_")[0], calendar['id'])
                return 200
Exemplo n.º 8
0
def eventAddFunction(args, data):
    calendar = gc.checkCalendar("eventsCalendar", "summary")

    if not calendar:
        newCalendar = {}
        newCalendar["summary"] = "eventsCalendar"

        calendar = gc.createCalendar(newCalendar)

    if ((args is None) or (args == '') or (args == []) or (len(
        (' '.join(args)).split('|')) != 5)
            or (' '.join(args).split('|')[0].strip() == "")
            or (' '.join(args).split('|')[1].strip() == "")):
        return None
    else:
        date = translateStringToDatetime(
            date=(' '.join(args)).split('|')[1].strip())

        if (date['dateStart'] == None or date['dateEnd'] == None):
            return 1

        event = {
            'summary': (' '.join(args)).split('|')[0],
            'description': '|/|'.join(
                (' '.join(args)).split('|')[2:]) + '/&/' + data,
            'start': {
                'dateTime':
                timezone('Europe/Madrid').localize(
                    date['dateStart']).astimezone(
                        timezone('UTC')).strftime("%Y-%m-%dT%XZ"),
            },
            'end': {
                'dateTime':
                timezone('Europe/Madrid').localize(date['dateEnd']).astimezone(
                    timezone('UTC')).strftime("%Y-%m-%dT%XZ"),
            },
        }

        return gc.createEvent(event=event, calendarId=calendar['id'])