<commit_before>#!/usr/bin/env python

import sys
import os.path

from oauth2client.file import Storage
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.tools import run
from flask import Flask

app = Flask(__name__)
app.config.from_envvar('JARVIS_SETTINGS')
config = app.config['JOBS']['calendar']


def main():
    if 'client_id' not in config \
            or 'client_secret' not in config \
            or 'api_key' not in config:
        print ('Error: client_id, client_secret or api_key is not set.\n\n'
               'Please create a client ID and server key here and update '
               'config.py:\n\nhttps://code.google.com/apis/console/#:access')
        sys.exit(1)

    FLOW = OAuth2WebServerFlow(
        client_id=config['client_id'],
        client_secret=config['client_secret'],
        scope='https://www.googleapis.com/auth/calendar.readonly')

    credentials_file = os.path.abspath(os.path.join(os.path.dirname(__file__),
                                       '..', 'app', 'jobs', '.calendar.json'))
    storage = Storage(credentials_file)
    credentials = storage.get()
    if credentials is None or credentials.invalid:
        credentials = run(FLOW, storage)
    else:
        print 'Google API credentials already exist: %s' % (credentials_file,)<commit_msg>Ensure env var is relative to app path<commit_after>#!/usr/bin/env python

import sys
import os.path

from oauth2client.file import Storage
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.tools import run
from flask import Flask

app = Flask(__name__, instance_relative_config=True,
            instance_path=os.path.abspath(os.path.join(
                os.path.dirname(__file__), '..', 'app')))
app.config.from_envvar('JARVIS_SETTINGS')
config = app.config['JOBS']['calendar']


def main():
    if 'client_id' not in config \
            or 'client_secret' not in config \
            or 'api_key' not in config:
        print ('Error: client_id, client_secret or api_key is not set.\n\n'
               'Please create a client ID and server key here and update '
               'config.py:\n\nhttps://code.google.com/apis/console/#:access')
        sys.exit(1)

    FLOW = OAuth2WebServerFlow(
        client_id=config['client_id'],
        client_secret=config['client_secret'],
        scope='https://www.googleapis.com/auth/calendar.readonly')

    credentials_file = os.path.join(app.instance_path, 'jobs',
                                    '.calendar.json')
    storage = Storage(credentials_file)
    credentials = storage.get()
    if credentials is None or credentials.invalid:
        credentials = run(FLOW, storage)
    else:
        print 'Google API credentials already exist: %s' % (credentials_file,)
{'fraction_non_alphanumeric': 0.11215970961887477, 'fraction_numerical': 0.004355716878402904, 'mean_word_length': 2.8545454545454545, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7558828', 'n_tokens_mistral': 829, 'n_tokens_neox': 814, 'n_words': 205}