def before_request():
	g.db = fitbit_db.fitbit_db(app.config['DATABASE'])

	g.site_root = ''
	if 'X-Script-Name' in request.headers:
		g.site_root = request.headers['X-Script-Name']

	g.host = 'localhost'
	if 'Host' in request.headers:
		g.host = request.headers['Host']

	g.meta = {'root': g.site_root}
def before_request():
	flask.g.db = fitbit_db.fitbit_db(app.config['DATABASE'])
	flask.g.host = flask.request.headers['Host'] or 'localhost'

	flask.g.site_root = ''
	if 'X-Script-Name' in flask.request.headers:
		flask.g.site_root = flask.request.headers['X-Script-Name']

	flask.g.host = 'localhost'
	if 'Host' in flask.request.headers:
		flask.g.host = flask.request.headers['Host']

	flask.g.meta = {'root': flask.g.site_root}
def update_user_meta ():
	while True:
		print("Fitbit Online Meta Update")
		db = fitbit_db.fitbit_db(app.config['DATABASE'])
		uffm = fitbit_manager.fitbit_manager(
			consumer_key=app.config['CONSUMER_KEY'],
			consumer_secret=app.config['CONSUMER_SECRET'],
			user_img_location=app.config['USER_IMG_LOCATION'],
			user_img_web_prefix=app.config['USER_IMG_WEB_PREFIX'])
		uffm.update_all_meta(db)
		db.close()
		# Sleep for an hour
		time.sleep(3600)	# Sleep operates in seconds, not minutes
def update_fitbit ():
	while True:
		print("Fitbit Online Update")
		db = fitbit_db.fitbit_db(app.config['DATABASE'])
		uffm = fitbit_manager.fitbit_manager(
			consumer_key=app.config['CONSUMER_KEY'],
			consumer_secret=app.config['CONSUMER_SECRET'],
			user_img_location=app.config['USER_IMG_LOCATION'],
			user_img_web_prefix=app.config['USER_IMG_WEB_PREFIX'])
		uffm.update(db=db, number_of_days=7)

		minutes = 60.0
		rate = math.ceil((minutes / app.config['REQUESTS_PER_HOUR']) * \
		            len(db.get_users()))
		rate += 1	# Reduce request rate as a safety margin
		db.close()
		print("Sleep Info. rate: {0}, current time: {1}".format(rate,
			datetime.datetime.now()))
		time.sleep(rate * 60)	# Sleep operates in seconds, not minutes
		# Sleep for an hour
		time.sleep(3600)	# Sleep operates in seconds, not minutes


parser = argparse.ArgumentParser()
parser.add_argument('--no-update',
                    action='store_true',
                    help="Do not retrieve information from Fitbit")
args = parser.parse_args()

# Create objects that we need for the application

app = flask.Flask(__name__)
app.config.from_object('fl_config')

db = fitbit_db.fitbit_db(app.config['DATABASE'])
fm = fitbit_manager.fitbit_manager(
	consumer_key=app.config['CONSUMER_KEY'],
	consumer_secret=app.config['CONSUMER_SECRET'],
	user_img_location=app.config['USER_IMG_LOCATION'],
	user_img_web_prefix=app.config['USER_IMG_WEB_PREFIX'])

fm.cache_images(db=db)


# Check if the user does not want to update from Fitbit
if not args.no_update:
	# Do an initial update to get a weeks worth of data at the least
	fm.update(db=db, number_of_days=7)
	fm.update_all_meta(db=db)
	fm.cache_images(db=db)
Exemplo n.º 6
0
def update_fitbit ():
	while True:
		ufdb = fitbit_db.fitbit_db('fitbit.db')
		uffm = fitbit_manager.fitbit_manager(ufdb)
		uffm.update()
		time.sleep(5)
Exemplo n.º 7
0
from threading import Timer
import time

from db import fitbit_db
import fitbit_manager

db = fitbit_db.fitbit_db('fitbit.db')
fm = fitbit_manager.fitbit_manager(db)

fm.update(7)
fm.retrieve()

def update_fitbit ():
	while True:
		ufdb = fitbit_db.fitbit_db('fitbit.db')
		uffm = fitbit_manager.fitbit_manager(ufdb)
		uffm.update()
		time.sleep(5)


t = Timer(3, update_fitbit)
t.start()