<commit_before>#!/usr/bin/python
'''*****************************************************************************************************************
    PiRemind
    By <NAME>

    This application connects to a Google Calendar and determines whether there are any appointments in the next
     few minutes and flashes some LEDs if there are. The project uses a Raspberry Pi 2 device with a Pimoroni Unicorn
     HAT (an 8x8 matrix of bright, tri-colored LEDs) to display an obnoxious reminder at 10 minutes, 5 miniutes and
     2 minutes.

    Google Calendar example code: https://developers.google.com/google-apps/calendar/quickstart/python
    Unicorn HAT example code: https://github.com/pimoroni/unicorn-hat/tree/master/python/examples
********************************************************************************************************************'''
from __future__ import print_function

import datetime
import os
import sys
import time

import httplib2
import oauth2client
import unicornhat as lights
from apiclient import discovery
from oauth2client import client
from oauth2client import tools

try:
    import argparse

    flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
except ImportError:
    flags = None

# If modifying these scopes, delete your previously saved credentials
# at ~/.credentials/client_secret.json
SCOPES = 'https://www.googleapis.com/auth/calendar.readonly'
CLIENT_SECRET_FILE = 'client_secret.json'
APPLICATION_NAME = 'Pi Remind'


def show_activity_light(status):
    global currentActivityLight

    # Turning on or off?
    if status:
        # on
        if currentActivityLight == 7:
            currentActivityLight = -1
        # increment the current light
        currentActivityLight += 1
        # set the pixel
        lights.set_pixel(currentActivityLight, 0, 0, 128, 0)
        # show the pixel
        lights.show()
    else:
        lights.off()


def flash_lights_orange(flashCount, delay, red, green, blue):
    for index in range(flashCount):
        for y in range(8):
            for x in range(8):
                lights.set_pixel(x, y, red, green, blue)
                lights.show()
        time.sleep(delay)
        lights.off()
        time.sleep(delay)


def get_credentials():
    # taken from https://developers.google.com/google-apps/calendar/quickstart/python
    home_dir = os.path.expanduser('~')
    credential_dir = os.path.join(home_dir, '.credentials')
    if not os.path.exists(credential_dir):
        os.makedirs(credential_dir)
    credential_path = os.path.join(credential_dir, 'pi_remind.json')
    store = oauth2client.file.Storage(credential_path)
    credentials = store.get()
    if not credentials or credentials.invalid:
        flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
        flow.user_agent = APPLICATION_NAME
        if flags:
            credentials = tools.run_flow(flow, store, flags)
        else:  # Needed only for compatibility with Python 2.6
            credentials = tools.run(flow, store)
        print('Storing credentials to ' + credential_path)
    return credentials


def getNextEvent(searchLimit):
    # modified from https://developers.google.com/google-apps/calendar/quickstart/python
    print('Getting next event')
    # get all of the events on the calendar from now through 10 minutes from now
    now = datetime.datetime.utcnow()
    then = now + datetime.timedelta(minutes=searchLimit)
    show_activity_light(True)
    # ask Google for the calendar entries
    eventsResult = service.events().list(
        calendarId='primary',
        timeMin=now.isoformat() + 'Z',
        timeMax=then.isoformat() + 'Z',
        # maxResults=10,
        singleEvents=True,
        orderBy='startTime').execute()
    show_activity_light(False)
    # Get the event list
    eventList = eventsResult.get('items', [])
    # did we get a return value?
    if not eventList:
        # no? Then no upcoming events at all.
        print(datetime.datetime.now(), "No entries returned")
        return None
    else:
        # we got a list, loop through them.
        for event in eventList:
            # we only care about events that have a start time
            start = event['start'].get('dateTime')
            if start:
                print("Event ", start, event['summary'])
                return event
            else:
                print("Skipping " + event['summary'])
<commit_msg>added extra return none to get events<commit_after>#!/usr/bin/python
'''*****************************************************************************************************************
    PiRemind
    By <NAME>

    This application connects to a Google Calendar and determines whether there are any appointments in the next
     few minutes and flashes some LEDs if there are. The project uses a Raspberry Pi 2 device with a Pimoroni Unicorn
     HAT (an 8x8 matrix of bright, tri-colored LEDs) to display an obnoxious reminder at 10 minutes, 5 miniutes and
     2 minutes.

    Google Calendar example code: https://developers.google.com/google-apps/calendar/quickstart/python
    Unicorn HAT example code: https://github.com/pimoroni/unicorn-hat/tree/master/python/examples
********************************************************************************************************************'''
from __future__ import print_function

import datetime
import os
import sys
import time

import httplib2
import oauth2client
import unicornhat as lights
from apiclient import discovery
from oauth2client import client
from oauth2client import tools

try:
    import argparse

    flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
except ImportError:
    flags = None

# If modifying these scopes, delete your previously saved credentials
# at ~/.credentials/client_secret.json
SCOPES = 'https://www.googleapis.com/auth/calendar.readonly'
CLIENT_SECRET_FILE = 'client_secret.json'
APPLICATION_NAME = 'Pi Remind'


def show_activity_light(status):
    global currentActivityLight

    # Turning on or off?
    if status:
        # on
        if currentActivityLight == 7:
            currentActivityLight = -1
        # increment the current light
        currentActivityLight += 1
        # set the pixel
        lights.set_pixel(currentActivityLight, 0, 0, 128, 0)
        # show the pixel
        lights.show()
    else:
        lights.off()


def flash_lights_orange(flashCount, delay, red, green, blue):
    for index in range(flashCount):
        for y in range(8):
            for x in range(8):
                lights.set_pixel(x, y, red, green, blue)
                lights.show()
        time.sleep(delay)
        lights.off()
        time.sleep(delay)


def get_credentials():
    # taken from https://developers.google.com/google-apps/calendar/quickstart/python
    home_dir = os.path.expanduser('~')
    credential_dir = os.path.join(home_dir, '.credentials')
    if not os.path.exists(credential_dir):
        os.makedirs(credential_dir)
    credential_path = os.path.join(credential_dir, 'pi_remind.json')
    store = oauth2client.file.Storage(credential_path)
    credentials = store.get()
    if not credentials or credentials.invalid:
        flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
        flow.user_agent = APPLICATION_NAME
        if flags:
            credentials = tools.run_flow(flow, store, flags)
        else:  # Needed only for compatibility with Python 2.6
            credentials = tools.run(flow, store)
        print('Storing credentials to ' + credential_path)
    return credentials


def getNextEvent(searchLimit):
    # modified from https://developers.google.com/google-apps/calendar/quickstart/python
    print('Getting next event')
    # get all of the events on the calendar from now through 10 minutes from now
    now = datetime.datetime.utcnow()
    then = now + datetime.timedelta(minutes=searchLimit)
    show_activity_light(True)
    # ask Google for the calendar entries
    eventsResult = service.events().list(
        calendarId='primary',
        timeMin=now.isoformat() + 'Z',
        timeMax=then.isoformat() + 'Z',
        # maxResults=10,
        singleEvents=True,
        orderBy='startTime').execute()
    show_activity_light(False)
    # Get the event list
    eventList = eventsResult.get('items', [])
    # did we get a return value?
    if not eventList:
        # no? Then no upcoming events at all.
        print(datetime.datetime.now(), "No entries returned")
        return None
    else:
        # we got a list, loop through them.
        for event in eventList:
            # we only care about events that have a start time
            start = event['start'].get('dateTime')
            # return the first event that has a start time
            if start:
                print("Event ", start, event['summary'])
                return event
            else:
                # otherwise skip the event
                print("Skipping " + event['summary'])
        # if we got this far and haven't returned anything, then there's no appointments in the specified time
        # window. So, return None
        return None

{'fraction_non_alphanumeric': 0.13212068402134844, 'fraction_numerical': 0.006317394619322514, 'mean_word_length': 2.988705473501303, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 10, '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': '698113', 'n_tokens_mistral': 2550, 'n_tokens_neox': 2431, 'n_words': 756}