-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
26 lines (21 loc) · 851 Bytes
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
import control.constants
# Necessary since tests and experiments are run from different contexts.
assert control.constants.PROJECT_FOLDER
gauth = GoogleAuth(settings_file=control.constants.PROJECT_FOLDER + '/cloud_interface/settings.yaml')
# Try to load saved client credentials
CREDENTIALS = control.constants.PROJECT_FOLDER + control.constants.VALIDATED_CREDENTIAL_FILE
gauth.LoadCredentialsFile(CREDENTIALS)
if gauth.credentials is None:
# Authenticate if they're not there.
gauth.LocalWebserverAuth()
elif gauth.access_token_expired:
# Refresh them if expired.
gauth.Refresh()
else:
# Initialize the saved credentials.
gauth.Authorize()
# Save the current credentials to a file
gauth.SaveCredentialsFile(CREDENTIALS)
drive = GoogleDrive(gauth)