import consul
import json 

USER_DETAILS_FILE = 'user_details.json'  # user details file


c = consul.Consul(host='192.168.1.237')

# def _get_user_details():
#     """
#     The specific user that you want to retrieve data for.
#     """
#     with open(USER_DETAILS_FILE) as f:
#         fitbit_user = json.load(f)
#         access_token = fitbit_user['access_token']
#         refresh_token = fitbit_user['refresh_token']
#         expires_at = fitbit_user['expires_at']

#     return access_token, refresh_token, expires_at

def _set_user_details(access_token, refresh_token, expires_at):
    c.kv.put('access_token', access_token)
    c.kv.put('refresh_token', refresh_token)
    c.kv.put('expires_at', str(expires_at))

def _get_user_details():
    access_token = c.kv.get('access_token')[1]["Value"].decode("utf-8")
    refresh_token = c.kv.get('refresh_token')[1]["Value"].decode("utf-8")
    expires_at = c.kv.get('expires_at')[1]["Value"].decode("utf-8")
    return access_token, refresh_token, expires_at




# access_token, refresh_token, expires_at = _get_user_details()
# store_user_details(access_token, refresh_token, expires_at)

access_token, refresh_token, expires_at = _get_user_details()

print(access_token)
print(expires_at)
print(refresh_token)

# print(access_token[1]["Value"].decode("utf-8"))
# print(refresh_token[1]["Value"].decode("utf-8"))
# print(expires_at[1]["Value"].decode("utf-8"))

