<s> from . import requires , today_utc <EOL> import requests <EOL> from datetime import timedelta <EOL> DAYS_BACK = <NUM_LIT:4> <EOL> @ requires ( '<STR_LIT>' ) <EOL> def sleeps ( gauge_factory , config , logger ) : <EOL> gauge = gauge_factory ( '<STR_LIT>' ) <EOL> access_token = config [ '<STR_LIT>' ] <EOL> headers = { '<STR_LIT>' : '<STR_LIT>' . format ( access_token ) } <EOL> r = requests . get ( '<STR_LIT>' , <EOL> headers = headers ) <EOL> for i in range ( DAYS_BACK ) : <EOL> day = today_utc ( ) - timedelta ( days = i ) <EOL> resp = r . json ( ) <EOL> sleeps = resp [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] <EOL> day_date = day . date ( ) <EOL> today_fmt = int ( day_date . strftime ( '<STR_LIT>' ) ) <EOL> today_sleeps = filter ( lambda s : s [ '<STR_LIT:date>' ] == today_fmt , sleeps ) <EOL> duration = sum ( [ s [ '<STR_LIT>' ] [ '<STR_LIT>' ] - s [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> for s in today_sleeps ] ) / <NUM_LIT> <EOL> if duration == <NUM_LIT:0> : <EOL> logger . info ( '<STR_LIT>' . format ( day_date ) ) <EOL> else : <EOL> gauge . save ( day , duration ) <EOL> logger . info ( '<STR_LIT>' . format ( duration , day_date ) ) <EOL> @ requires ( '<STR_LIT>' ) <EOL> def steps ( gauge_factory , config , logger ) : <EOL> gauge = gauge_factory ( '<STR_LIT>' ) <EOL> access_token = config [ '<STR_LIT>' ] <EOL> headers = { '<STR_LIT>' : '<STR_LIT>' . format ( access_token ) } <EOL> r = requests . get ( '<STR_LIT>' , <EOL> headers = headers ) <EOL> for i in range ( DAYS_BACK ) : <EOL> day = today_utc ( ) - timedelta ( days = i ) <EOL> resp = r . json ( ) <EOL> moves = resp [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] <EOL> day_date = day . date ( ) <EOL> today_fmt = int ( day_date . strftime ( '<STR_LIT>' ) ) <EOL> today_moves = filter ( lambda m : m [ '<STR_LIT:date>' ] == today_fmt , moves ) <EOL> steps = sum ( [ m [ '<STR_LIT>' ] [ '<STR_LIT>' ] for m in today_moves ] ) <EOL> if steps == <NUM_LIT:0> : <EOL> logger . info ( '<STR_LIT>' . format ( day_date ) ) <EOL> else : <EOL> gauge . save ( day , steps ) <EOL> logger . info ( '<STR_LIT>' . format ( steps , day_date ) ) <EOL> @ requires ( '<STR_LIT>' ) <EOL> def caffeine ( gauge_factory , config , logger ) : <EOL> gauge = gauge_factory ( '<STR_LIT>' ) <EOL> access_token = config [ '<STR_LIT>' ] <EOL> headers = { '<STR_LIT>' : '<STR_LIT>' . format ( access_token ) } <EOL> r = requests . get ( '<STR_LIT>' , <EOL> headers = headers ) <EOL> for i in range ( DAYS_BACK ) : <EOL> day = today_utc ( ) - timedelta ( days = i ) <EOL> resp = r . json ( ) <EOL> meals = resp [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] <EOL> day_date = day . date ( ) <EOL> today_fmt = int ( day_date . strftime ( '<STR_LIT>' ) ) <EOL> today_meals = filter ( lambda m : m [ '<STR_LIT:date>' ] == today_fmt , meals ) <EOL> caffeine = sum ( [ m [ '<STR_LIT>' ] [ '<STR_LIT>' ] for m in today_meals ] ) <EOL> if caffeine == <NUM_LIT:0> : <EOL> logger . info ( '<STR_LIT>' . format ( day_date ) ) <EOL> else : <EOL> gauge . save ( day , caffeine ) <EOL> logger . info ( '<STR_LIT>' . format ( caffeine , day_date ) ) <EOL> @ requires ( '<STR_LIT>' ) <EOL> def heart_rate ( gauge_factory , config , logger ) : <EOL> gauge = gauge_factory ( '<STR_LIT>' ) <EOL> access_token = config [ '<STR_LIT>' ] <EOL> headers = { '<STR_LIT>' : '<STR_LIT>' . format ( access_token ) } <EOL> r = requests . get ( '<STR_LIT>' , <EOL> headers = headers ) <EOL> for i in range ( DAYS_BACK ) : <EOL> day = today_utc ( ) - timedelta ( days = i ) <EOL> resp = r . json ( ) <EOL> items = resp [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] <EOL> day_date = day . date ( ) <EOL> today_fmt = int ( day_date . strftime ( '<STR_LIT>' ) ) <EOL> today = filter ( lambda hr : hr [ '<STR_LIT:date>' ] == today_fmt , items ) <EOL> if not today or len ( today ) == <NUM_LIT:0> or not today [ <NUM_LIT:0> ] [ '<STR_LIT>' ] : <EOL> logger . info ( '<STR_LIT>' . format ( day_date ) ) <EOL> else : <EOL> hr = today [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> gauge . save ( day , hr ) <EOL> logger . info ( '<STR_LIT>' . format ( hr , day_date ) ) </s>
