Esempio n. 1
0
def write_csv_file():
    db = Mariadb()
    query = db.query('SELECT * FROM temperature_tbl;')
    csv_file = open(csv_filename(), 'a')
    csv_attachment = csv.writer(csv_file)
    csv_attachment.writerows(query)
    csv_file.close()
    return
Esempio n. 2
0
def remove_mariadb():
    cmd = 'rm ' + os.path.abspath('daily_reports/report-*')
    os.system(cmd)
    try:
        db = Mariadb()
        db.execute('DROP TABLE temperature_tbl;')
        print "\t\tDROP TABLE"
    except:
        pass
    return
Esempio n. 3
0
def create_mariadb():
    try:
        db = Mariadb()
        db.execute("CREATE TABLE IF NOT EXISTS temperature_tbl"
                "(id INT(20) NOT NULL AUTO_INCREMENT," 
                "degree VARCHAR(8)," 
                "date VARCHAR(24)," 
                "PRIMARY KEY(id));")
        print "\t\tCREATE TABLE"
    except:
        pass
    return
Esempio n. 4
0
def html_db_table(sql):
    db = Mariadb()
    return query_to_html(db.get_rows(sql))
Esempio n. 5
0
def insert_mariadb(data, alert):
    db = Mariadb()
    db.execute('INSERT INTO temperature_tbl (degree, status, date) VALUES ("{}", "{}", "{}");'.format(data, str(alert), str(time.ctime())))
    return