import datetime import time import dropbox from dropbox.files import WriteMode from dropbox.exceptions import ApiError, AuthError import sys,os import firebase_handler as fbh TOKEN=fbh.fb_get("d2_accesstoken") APP_KEY=os.environ['DROPBOX_APP_KEY'] APP_SECRET=os.environ['DROPBOX_APP_SECRET'] REFRESH_TOKEN=fbh.fb_get("d2_refreshtoken") #os.environ['DROP_DIR2']="C:/dockers/chroma/chroma1/" #os.environ['APP_PATH']="/" print("token::",TOKEN) with dropbox.Dropbox(oauth2_access_token=TOKEN,app_key=APP_KEY,app_secret=APP_SECRET,oauth2_refresh_token=REFRESH_TOKEN) as dbx: #,app_key=APP_KEY,app_secret=APP_SECRET,oauth2_refresh_token=REFRESH_TOKEN) as dbx: # Check that the access token is valid try: dbx.users_get_current_account() if (TOKEN != dbx._oauth2_access_token): fbh.fb_update("d2_accesstoken",dbx._oauth2_access_token) TOKEN=dbx._oauth2_access_token print("dropbox connection ok,",dbx._oauth2_access_token) print(dbx._oauth2_refresh_token) except AuthError: try: dbx.check_and_refresh_access_token() fbh.fb_update("d2_accesstoken",dbx._oauth2_access_token) print("dropbox connection refreshed and updated",dbx._oauth2_access_token) print(dbx._oauth2_refresh_token) except Exception: sys.exit("ERROR: Invalid access token; try re-generating an " "access token from the app console on the web.") def normalizeFilename(filename): while '//' in filename: filename = filename.replace('//', '/') return filename def getDropboxFilename(localFilename): """ localFilename is $DROP_DIR2//""" """ dropboxFilename is $APP_PATH///""" """ dropboxFilename is $APP_PATH//