<commit_before>import httplib2
from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials
from viaduct import application
import traceback

# google calendar Settings > via_events > id
via_calendar_id = "<EMAIL>"
via_lezingen_id = "<EMAIL>"

# Google API service account email
service_email = ('614222921385-1lrc4bkrq51mb4ra4dl8g2f1hi8232e2'
                 '@developer.<EMAIL>account.com')

# name of the private key file
private_key = application.config['GOOGLE_API_KEY']


def build_service():
    try:
        f = open(private_key, "rb")
        key = f.read()
        f.close()

        credentials = SignedJwtAssertionCredentials(
            service_email,
            key,
            scope="https://www.googleapis.com/auth/calendar",
            sub='<EMAIL>'
        )

        # Create an authorized http instance
        http = httplib2.Http()
        http = credentials.authorize(http)

        return build("calendar", "v3", http=http)
    except Exception:
        traceback.print_exc()
        return None


def insert_activity(title, description, location, start, end):
    """Helper method to insert a via activity"""
    return insert_event(
        title,
        description,
        location,
        start,
        end,
        via_calendar_id
    )


# Helper method to insert a via_lezing
def insert_lecture(title, description, location, start, end):
    return insert_event(
        title,
        location,
        start,
        end,
        via_lezingen_id
    )


# Provide a calendar_id
def insert_event(title="", description='', location="VIA kamer", start="",
                 end="", calendar_id=None):
    service = build_service()

    if service:
        # Event to insert
        event = {
            'summary': title,
            'description': description,
            'location': location,
            'start': {'dateTime': start, 'timeZone': 'Europe/Amsterdam'},
            'end': {'dateTime': end,     'timeZone': 'Europe/Amsterdam'}
        }

        if application.debug:
            return None
        return service.events() \
            .insert(calendarId=calendar_id, body=event) \
            .execute()


def update_activity(event_id, title, description, location, start, end):
    return update_event(
        event_id,
        title,
        description,
        location,
        start,
        end,
        via_calendar_id
    )


def update_lecture(event_id, title, location, start, end):
    return update_event(
        event_id,
        title,
        location,
        start,
        end,
        via_lezingen_id
    )


def update_event(event_id, title="", description='', location="VIA Kamer",
                 start="", end="", calendar_id=None):
    service = build_service()

    if service:
        # Event to update
        event = {
            'summary': title,
            'description': description,
            'location': location,
            'start': {'dateTime': start, 'timeZone': 'Europe/Amsterdam'},
            'end': {'dateTime': end,     'timeZone': 'Europe/Amsterdam'}
        }

        if application.debug:
            return None

        return service.events() \
            .update(calendarId=calendar_id, eventId=event_id, body=event) \
            .execute()


def delete_activity(event_id):
    return delete_event(event_id, via_calendar_id)


def delete_lecture(event_id):
    return delete_event(event_id, via_lezingen_id)


# Delete an event
def delete_event(event_id, calendar_id=None):
    service = build_service()

    if service:
        return service.events() \
            .delete(calendarId=calendar_id, eventId=event_id) \
            .execute()
<commit_msg>Remove lecture calendar code<commit_after>import httplib2
from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials
from viaduct import application
import traceback

# google calendar Settings > via_events > id
via_calendar_id = "<EMAIL>"

# Google API service account email
service_email = ('614222921385-1lrc4bkrq51mb4ra4dl8g2f1hi8232e2'
                 '@developer.gserviceaccount.com')

# name of the private key file
private_key = application.config['GOOGLE_API_KEY']


def build_service():
    try:
        f = open(private_key, "rb")
        key = f.read()
        f.close()

        credentials = SignedJwtAssertionCredentials(
            service_email,
            key,
            scope="https://www.googleapis.com/auth/calendar",
            sub='<EMAIL>'
        )

        # Create an authorized http instance
        http = httplib2.Http()
        http = credentials.authorize(http)

        return build("calendar", "v3", http=http)
    except Exception:
        traceback.print_exc()
        return None


def insert_activity(title, description, location, start, end):
    """Helper method to insert a via activity"""
    return insert_event(
        title,
        description,
        location,
        start,
        end,
        via_calendar_id
    )


# Provide a calendar_id
def insert_event(title="", description='', location="VIA kamer", start="",
                 end="", calendar_id=None):
    service = build_service()

    if service:
        # Event to insert
        event = {
            'summary': title,
            'description': description,
            'location': location,
            'start': {'dateTime': start, 'timeZone': 'Europe/Amsterdam'},
            'end': {'dateTime': end,     'timeZone': 'Europe/Amsterdam'}
        }

        if application.debug:
            return None
        return service.events() \
            .insert(calendarId=calendar_id, body=event) \
            .execute()


def update_activity(event_id, title, description, location, start, end):
    return update_event(
        event_id,
        title,
        description,
        location,
        start,
        end,
        via_calendar_id
    )


def update_event(event_id, title="", description='', location="VIA Kamer",
                 start="", end="", calendar_id=None):
    service = build_service()

    if service:
        # Event to update
        event = {
            'summary': title,
            'description': description,
            'location': location,
            'start': {'dateTime': start, 'timeZone': 'Europe/Amsterdam'},
            'end': {'dateTime': end,     'timeZone': 'Europe/Amsterdam'}
        }

        if application.debug:
            return None

        return service.events() \
            .update(calendarId=calendar_id, eventId=event_id, body=event) \
            .execute()


def delete_activity(event_id):
    return delete_event(event_id, via_calendar_id)


# Delete an event
def delete_event(event_id, calendar_id=None):
    service = build_service()

    if service:
        return service.events() \
            .delete(calendarId=calendar_id, eventId=event_id) \
            .execute()

{'fraction_non_alphanumeric': 0.1054534934181976, 'fraction_numerical': 0.008679299869810501, 'mean_word_length': 2.273674242424242, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2738545', 'n_tokens_mistral': 1992, 'n_tokens_neox': 1954, 'n_words': 475}