<s> """<STR_LIT>""" <EOL> from time import mktime , sleep <EOL> from datetime import datetime , timedelta <EOL> from os import path <EOL> import ConfigParser <EOL> import sqlite3 <EOL> import fitbit <EOL> CONFIG = ConfigParser . ConfigParser ( ) <EOL> CONFIG . read ( [ "<STR_LIT>" , path . expanduser ( "<STR_LIT>" ) ] ) <EOL> DB_FILE = path . expanduser ( CONFIG . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def client ( ) : <EOL> return fitbit . Client ( CONFIG . get ( '<STR_LIT>' , '<STR_LIT>' ) , CONFIG . get ( '<STR_LIT>' , '<STR_LIT>' ) , CONFIG . get ( '<STR_LIT>' , '<STR_LIT>' ) , CONFIG . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def create_table ( table , db ) : <EOL> db . execute ( "<STR_LIT>" % ( table , table ) ) <EOL> db . execute ( "<STR_LIT>" % ( table , table ) ) <EOL> """<STR_LIT>""" <EOL> def connect_db ( filename ) : <EOL> if path . isfile ( filename ) : <EOL> return sqlite3 . connect ( filename ) <EOL> else : <EOL> db = sqlite3 . connect ( filename ) <EOL> create_table ( "<STR_LIT>" , db ) <EOL> create_table ( "<STR_LIT>" , db ) <EOL> create_table ( "<STR_LIT>" , db ) <EOL> create_table ( "<STR_LIT>" , db ) <EOL> return db <EOL> def dump_to_db ( db , data_type , date , data ) : <EOL> insertString = "<STR_LIT>" % data_type <EOL> sum = <NUM_LIT:0> <EOL> for row in data : <EOL> db . execute ( insertString , ( mktime ( row [ <NUM_LIT:0> ] . timetuple ( ) ) , row [ <NUM_LIT:1> ] ) ) <EOL> sum += row [ <NUM_LIT:1> ] <EOL> db . execute ( "<STR_LIT>" % data_type , ( mktime ( date . timetuple ( ) ) , sum ) ) <EOL> db . commit ( ) <EOL> def dump_day ( db , date ) : <EOL> c = client ( ) <EOL> dump_to_db ( db , "<STR_LIT>" , date , c . intraday_steps ( date ) ) <EOL> sleep ( <NUM_LIT:1> ) <EOL> dump_to_db ( db , "<STR_LIT>" , date , c . intraday_calories_burned ( date ) ) <EOL> sleep ( <NUM_LIT:1> ) <EOL> dump_to_db ( db , "<STR_LIT>" , date , c . intraday_active_score ( date ) ) <EOL> sleep ( <NUM_LIT:1> ) <EOL> dump_to_db ( db , "<STR_LIT>" , date , c . intraday_sleep ( date ) ) <EOL> sleep ( <NUM_LIT:1> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> db = connect_db ( DB_FILE ) <EOL> dump_day ( db , ( datetime . now ( ) . date ( ) - timedelta ( days = <NUM_LIT:1> ) ) ) <EOL> db . close ( ) </s>
