import MySQLdb as mdb import sys import json import MySQLdb import sys host = "localhost" db_id = "root" db_pw = "1q2w3e" db_name = "fitbit_db" db = MySQLdb.connect( host, db_id, db_pw, db_name ) cursor = db.cursor() #cursor.execute( "select version()" ) #data = cursor.fetchone() #cursor.execute( "show tables") #data = cursor.fetchall() #print data # 001_sleep_start.txt with open('001_sleep_start.txt') as f: data = f.read() jsondata = json.loads(data) for row in jsondata['sleep-startTime']: a = row['value'] b = row['dateTime'] cursor.execute("INSERT INTO Sleep_start VALUES(%s , %s)",(a,b)) data = cursor.fetchall() # 002_sleep_timeInBed.txt with open('002_sleep_timeInBed.txt') as a: timeinbed = a.read() timeinbed_1 = json.loads(timeinbed) for row1 in timeinbed_1['sleep-timeInBed']: a = row1['value'] b = row1['dateTime'] cursor.execute("INSERT INTO Sleep_timeinbed VALUES(%s , %s)",(a,b)) data = cursor.fetchall() #003_sleep_minutesAsleep.txt with open('003_sleep_minutesAsleep.txt') as a: timeinbed = a.read() timeinbed_1 = json.loads(timeinbed) for row1 in timeinbed_1['sleep-minutesAsleep']: a = row1['value'] b = row1['dateTime'] cursor.execute("INSERT INTO sleep-minutesAsleep VALUES(%s , %s)",(a,b)) data = cursor.fetchall() #004_sleep_awakeningsCount.txt with open('004_sleep_awakeningsCount.txt') as a: timeinbed = a.read() timeinbed_1 = json.loads(timeinbed) for row1 in timeinbed_1['sleep_awakeningsCount']: a = row1['value'] b = row1['dateTime'] cursor.execute("INSERT INTO sleep_awakeningsCount VALUES(%s , %s)",(a,b)) data = cursor.fetchall() # 005_sleep_minutesAwake.txt with open('005_sleep_minutesAwake.txt') as a: timeinbed = a.read() timeinbed_1 = json.loads(timeinbed) for row1 in timeinbed_1['sleep-timeInBed']: a = row1['value'] b = row1['dateTime'] cursor.execute("INSERT INTO sleep_minutesAwake VALUES(%s , %s)",(a,b)) data = cursor.fetchall() # 006_sleep_minutesToFallAsleep.txt with open('006_sleep_minutesToFallAsleep.txt') as a: timeinbed = a.read() timeinbed_1 = json.loads(timeinbed) for row1 in timeinbed_1['sleep_minutesToFallAsleep']: a = row1['value'] b = row1['dateTime'] cursor.execute("INSERT INTO sleep_minutesToFallAsleep VALUES(%s , %s)",(a,b)) data = cursor.fetchall() # 007_sleep_minutesAfterWakeup.txt with open('007_sleep_minutesAfterWakeup.txt') as a: timeinbed = a.read() timeinbed_1 = json.loads(timeinbed) for row1 in timeinbed_1['sleep_minutesAfterWakeup']: a = row1['value'] b = row1['dateTime'] cursor.execute("INSERT INTO sleep_minutesAfterWakeup VALUES(%s , %s)",(a,b)) data = cursor.fetchall() # 008_sleep_efficiency.txt with open('008_sleep_efficiency.txt') as a: timeinbed = a.read() timeinbed_1 = json.loads(timeinbed) for row1 in timeinbed_1['sleep-timeInBed']: a = row1['value'] b = row1['dateTime'] cursor.execute("INSERT INTO sleep_efficiency VALUES(%s , %s)",(a,b)) data = cursor.fetchall() db.close()
카테고리 없음