Database Insert Python
2019. 12. 28. 21:11
Programing/Raspberry Pi)
# -*- coding: utf-8 -*-
import pymysql
import time
import datetime
#글로벌변수설정
nowdate = "" # 날짜&시간
nowtime = "" # 시간
startTime=''
endTime =''
# ____gipo 핀 세팅___#
gpio.cleanup()
gpio.setmode(gpio.BCM)
def insertDB():
conn = pymysql.connect(host='localhost', port=3306, user='id', passwd='passwd')
sql = "INSERT INTO hackathon.datalist ( `filed1`, `filed2`, `filed3`, `filed4`, `filed5`, `filed6`) VALUES(%s,%s,%s,%s,%s,%s);"
cur = conn.cursor()
nowdate_f()
global nowdate,startTime,endTime,cnt_One,cnt_Two,cnt_Tree
val = (nowdate,startTime,endTime,cnt_One,cnt_Two,cnt_Tree)
cur.execute(sql, val)
conn.commit()
cur.close()
conn.close()
# 시간 함수__DEBTOLEE
def nowdate_f():
# DATE
global nowdate
nowtemp = ''
nowtemp = datetime.datetime.now()
nowdate = nowtemp.strftime('%Y-%m-%d')
def nowtime_f():
global nowtime
nowtemp = ''
nowtemp = datetime.datetime.now()
nowtime = nowtemp.strftime('%H:%M')
return nowtime
'Programing > Raspberry Pi)' 카테고리의 다른 글
Project2020 (0) | 2020.03.09 |
---|---|
Multiprocessing Python (0) | 2019.12.28 |
Buzzer Python (0) | 2019.12.28 |
Ultra(초음파) Python (0) | 2019.12.28 |
LED Python (0) | 2019.12.28 |