Spaces:
Paused
Paused
Download generate_drive_token.py from prad9036temp/leech: direct link, hf CLI and curl.
- Browser
- Download file 891 Bytes
-
https://huggingface.co/spaces/prad9036temp/leech/resolve/main/generate_drive_token.py
- Command line
-
hf download hf://spaces/prad9036temp/leech/generate_drive_token.py
-
curl -L -o generate_drive_token.py https://huggingface.co/spaces/prad9036temp/leech/resolve/main/generate_drive_token.py
891 Bytes
| import os | |
| import pickle | |
| from google.auth.transport.requests import Request | |
| from google_auth_oauthlib.flow import InstalledAppFlow | |
| credentials = None | |
| __G_DRIVE_TOKEN_FILE = "token.pickle" | |
| __OAUTH_SCOPE = ["https://www.googleapis.com/auth/drive"] | |
| if os.path.exists(__G_DRIVE_TOKEN_FILE): | |
| with open(__G_DRIVE_TOKEN_FILE, "rb") as f: | |
| credentials = pickle.load(f) | |
| if ( | |
| (credentials is None or not credentials.valid) | |
| and credentials | |
| and credentials.expired | |
| and credentials.refresh_token | |
| ): | |
| credentials.refresh(Request()) | |
| else: | |
| flow = InstalledAppFlow.from_client_secrets_file("credentials.json", __OAUTH_SCOPE) | |
| credentials = flow.run_local_server(port=0, open_browser=False) | |
| # Save the credentials for the next run | |
| with open(__G_DRIVE_TOKEN_FILE, "wb") as token: | |
| pickle.dump(credentials, token) | |