def animal_out(): db = MySQL().connect() cursor = db.cursor() sql = 'SELECT * FROM ANIMAL_OUTS' cursor.execute(sql) results = cursor.fetchall() return render_template('animal_out.html', results=results)
class AnimalIn(Resource): def __init__(self): self.db = MySQL().connect() def get(self): self.cursor = self.db.cursor() self.sql = 'SELECT * FROM ANIMAL_INS' self.cursor.execute(self.sql) self.rows = self.cursor.fetchall() self.db.close() for r in self.rows: r['DATETIME'] = str(r['DATETIME']) return self.rows
# Create CSV File pathfile = "C:\Code\Datadog\\" pathfile_mysql = "C:/Code/Datadog/" csv = write_csv.write_csv(file_date, data_list, pathfile, metric, list_column) filename = pathfile + metric + '_' + file_date + '.csv' filename_mysql = pathfile_mysql + metric + '_' + file_date + '.csv' get_metric.silentremove(jsonfile) # ETL to Database table = "dd_" + metric.replace('.', '_') + "_hourly" # MySQL Database host = DatabaseDetail.Database_Connection['MySQL']['host'] username = DatabaseDetail.Database_Connection['MySQL']['username'] pwd = DatabaseDetail.Database_Connection['MySQL']['pwd'] dbname = DatabaseDetail.Database_Connection['MySQL']['dbname'] MySQL.insertdbmysqlconnector(filename_mysql, host, username, pwd, dbname, table, ystarttime, yendtime) # BQ Database project_id = DatabaseDetail.Database_Connection['BigQuery'][ 'project_id'] dataset_id = DatabaseDetail.Database_Connection['BigQuery'][ 'dataset_id'] BigQuery.insertBQ(filename, project_id, dataset_id, table, ystarttime, yendtime)
def __init__(self): self.db = MySQL().connect()