mirror of
https://github.com/anasty17/mirror-leech-telegram-bot.git
synced 2025-01-05 10:36:52 +08:00
6fe2510dca
- To upload with bot and user session with respect to file size - Handle object expire while sending media group for parts Signed-off-by: anasty17 <e.anastayyar@gmail.com>
26 lines
891 B
Python
26 lines
891 B
Python
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)
|