def main():
    ''' This program will be able to execute multiple tasks 
        to fetch data and put it in Google Sheets
        
        Task:
            A task is a operation of fetching data from a MySql DataBase
            and uploads it to a Google Sheet
            
        How to make a new Task:
            1: Make a new directory in the 'tasks' directory
            2: Create a 'credentials.json' file
                - Read doc's in 'configuration.py' for layout
            3: Create a 'query.sql' file
    '''
    tasks_dir = "tasks/"

    for task in os.listdir(tasks_dir):
        if os.path.isdir('{}/{}'.format(tasks_dir, task)):
            config = Configuration(task_path=task)
            try:
                # Get data from database
                dbData = DataBase(config=config).getTableData()
                columns = dbData['column_names']
                data = dbData['table_data']

                # Upload data to sheet
                sheet = Sheet(config=config)
                sheet.clear_sheet()
                sheet.upload_data(columns=columns, data=data, date_time=True)
                printMessage("Completed task: " + task)
            except Exception as error:
                printMessage("{} => {}".format(task, error))
                traceback.print_exc()

    return 0
Example #2
0
from flask import Flask, request, session, g, redirect, url_for, abort, \
    render_template, flash
from sheets import Sheet
from local_settings import II_SHEET_ID, II_SHEET_RANGE

app = Flask(__name__)
app.config.from_object(__name__)

innovating_instruction = Sheet(
    II_SHEET_ID,
    II_SHEET_RANGE)


@app.route('/')
def hello_world():
    return render_template('map.html',
                           locations=innovating_instruction.get_locations())
Example #3
0
 def __init__(self):
     self.sheet = Sheet()
from lights import Light, LightSet
from sheets import Sheet
from time import sleep
from datetime import datetime, timedelta
from people import Person
import os

datasource = f'{os.environ["GOOGLE_SHEET_KEY"]}'

# dictionary to store current status
person_status = {'Zaks-iPhone': None, 'Louiseā€™s iPhone': None}

sheet = Sheet(datasource)

lights = LightSet()

for i in range(1, 13):
    lights.add_light(i, Light(i))

# louise = Person('Louise')
# zak = Person('Zak')

previous_index = None


async def poll_event(loop, prev_datetime):

    global previous_index

    records_since = sheet.get_records_since_index(previous_index)