import dropbox
from dotenv import load_dotenv
from pathlib import Path
import os
from dropbox import DropboxOAuth2FlowNoRedirect

load_dotenv(Path(__file__).parent / ".env")

APP_KEY = os.getenv("DROPBOX_APP_KEY", "")
APP_SECRET = os.getenv("DROPBOX_APP_SECRET", "")

auth_flow = DropboxOAuth2FlowNoRedirect(
    APP_KEY,
    APP_SECRET,
    token_access_type='offline'  # důležité — dá refresh token
)

authorize_url = auth_flow.start()
print(f"Otevři v prohlížeči:\n{authorize_url}")

auth_code = input("Vlož autorizační kód: ").strip()
oauth_result = auth_flow.finish(auth_code)

print(f"Refresh token: {oauth_result.refresh_token}")
# Tento token ulož — platí "navždy" (dokud app neodvoláš)