本文整理匯總了Python中fitbit.Fitbit.set_token方法的典型用法代碼示例。如果您正苦於以下問題:Python Fitbit.set_token方法的具體用法?Python Fitbit.set_token怎麽用?Python Fitbit.set_token使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類fitbit.Fitbit
的用法示例。
在下文中一共展示了Fitbit.set_token方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from fitbit import Fitbit [as 別名]
# 或者: from fitbit.Fitbit import set_token [as 別名]
#.........這裏部分代碼省略.........
if self.fitbit.get_token() is None:
stored_config_fitbit = keyring.get_password("Fitbit.com", "Fitbit")
self.logger.debug("Loaded fitbit config from keyring: {0}".format(stored_config_fitbit))
token = None
if stored_config_fitbit is None :
self.logger.error("Not authenticated to Fitbit.com. Please configure before use.")
return
else :
if (type(stored_config_fitbit) != dict):
stored_config_fitbit = json.loads(stored_config_fitbit)
if 'token' not in stored_config_fitbit :
self.logger.debug("Could not find Fitbit auth token in keyring");
if ('pin' in stored_config_fitbit) and ('req_token' in stored_config_fitbit):
self.logger.debug("Found pin {0} and req_token in keyring, attempting authorization to Fitbit.com".format(stored_config_fitbit['pin']))
try:
fitbit_token_config = {}
token = self.fitbit.get_token_with_pin(stored_fitbit_config['pin'], stored_fitbit_config['req_token'])
if token:
self.logger.debug("Got auth token {0}".format(token))
# self.logger.debug("Got auth token of type {0}".format(type(token)))
fitbit_token_config['token']=token
keyring.set_password("Fitbit.com", "Fitbit", json.dumps(fitbit_token_config))
except Exception as exc:
self.logger.error("Could not authorise to fitbit, error: {1}".format(exc))
return
else :
self.logger.debug("Could not find pin or req_token in keyring. Cannot attempt authorization to Fitbit.com.")
return
else:
token = stored_config_fitbit['token']
if token is not None :
self.fitbit.set_token(token)
self.config_start = datetime.strptime(stored_config_harvester['start'], "%Y-%m-%d")
self.config_box = stored_config_harvester['box']
self.config_indx_user = stored_config_harvester['user']
self.config_indx_pass = stored_config_harvester['password']
if 'overwrite' in stored_config_harvester :
self.config_overwrite = stored_config_harvester['overwrite']
def run(self):
args = vars(self.parser.parse_args())
self.logger.debug("Received arguments: {0}".format(args))
if args['config']:
self.set_config(args)
elif args['get_config']:
print self.get_config(args)
else:
self.logger.debug("Starting the harvester. ")
self.work(args['server'])
reactor.run()
def yesterday(self):
return datetime.combine((datetime.now()+timedelta(days=-1)).date(), time(00,00,00))
def today(self):
return datetime.combine(datetime.now().date(), time(00,00,00))
def get_indx(self, server_url):
indx_d = Deferred()
def authed_cb():
def token_cb(token):
indx = IndxClient(server_url, self.config_box, "INDX_Fitbit_Harvester", token = token, client = authclient.client)
indx_d.callback(indx)