Spaces:
Running
Running
Commit
·
eda303f
1
Parent(s):
213154b
remove unused drive related things
Browse files- evreal_cred.json +0 -13
- gdrive.py +0 -65
- requirements.txt +0 -1
evreal_cred.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"type": "service_account",
|
| 3 |
-
"project_id": "evreal",
|
| 4 |
-
"private_key_id": "***",
|
| 5 |
-
"private_key": "***",
|
| 6 |
-
"client_email": "[email protected]",
|
| 7 |
-
"client_id": "112071584481993672650",
|
| 8 |
-
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
| 9 |
-
"token_uri": "https://oauth2.googleapis.com/token",
|
| 10 |
-
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 11 |
-
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/evreal%40evreal.iam.gserviceaccount.com",
|
| 12 |
-
"universe_domain": "googleapis.com"
|
| 13 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gdrive.py
DELETED
|
@@ -1,65 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import json
|
| 3 |
-
|
| 4 |
-
from pydrive2.auth import GoogleAuth
|
| 5 |
-
from pydrive2.drive import GoogleDrive
|
| 6 |
-
from oauth2client.service_account import ServiceAccountCredentials
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
def login_with_service_account():
|
| 10 |
-
scope = ["https://www.googleapis.com/auth/drive"]
|
| 11 |
-
gauth = GoogleAuth()
|
| 12 |
-
gauth.auth_method = 'service'
|
| 13 |
-
cred_dict = json.load(open('evreal_cred.json', 'r'))
|
| 14 |
-
cred_dict['private_key_id'] = os.environ['PRIVATE_KEY_ID']
|
| 15 |
-
cred_dict['private_key'] = os.environ['PRIVATE_KEY'].replace('\\n', '\n')
|
| 16 |
-
gauth.credentials = ServiceAccountCredentials.from_json_keyfile_dict(cred_dict, scope)
|
| 17 |
-
return gauth
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
gauth = login_with_service_account()
|
| 21 |
-
drive = GoogleDrive(gauth)
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
def get_file_id_inside_folder(drive, folder_id, file_name):
|
| 25 |
-
file_list = drive.ListFile({'q': "'{}' in parents and trashed=false".format(folder_id)}).GetList()
|
| 26 |
-
for file in file_list:
|
| 27 |
-
if file['title'] == file_name:
|
| 28 |
-
return file['id']
|
| 29 |
-
return None
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
def get_file_id_for_file_path(drive, file_path):
|
| 33 |
-
# file_parts = os.path.split(file_path)
|
| 34 |
-
path = os.path.normpath(file_path)
|
| 35 |
-
file_parts = path.split(os.sep)
|
| 36 |
-
file_id = '1-5zmRu3Od9s2dYu1S01u4aC2ihAmo1K2'
|
| 37 |
-
for file_part in file_parts:
|
| 38 |
-
if file_part == '':
|
| 39 |
-
continue
|
| 40 |
-
file_id = get_file_id_inside_folder(drive, file_id, file_part)
|
| 41 |
-
if file_id is None:
|
| 42 |
-
return None
|
| 43 |
-
|
| 44 |
-
return file_id
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
def download_file(file_path, local_path):
|
| 48 |
-
file_id = get_file_id_for_file_path(drive, file_path)
|
| 49 |
-
if file_id is None:
|
| 50 |
-
return False
|
| 51 |
-
file = drive.CreateFile({'id': file_id})
|
| 52 |
-
os.makedirs(os.path.dirname(local_path), exist_ok=True)
|
| 53 |
-
file.GetContentFile(local_path)
|
| 54 |
-
return True
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
# test if main
|
| 58 |
-
if __name__ == "__main__":
|
| 59 |
-
drive_file_path = "0000_000000/ECD_calibration/videos/recon.mp4"
|
| 60 |
-
# drive_file_path = "test.txt"
|
| 61 |
-
local_file_path = os.path.join("temp_data", drive_file_path)
|
| 62 |
-
# gauth = login_with_service_account()
|
| 63 |
-
# drive = GoogleDrive(gauth)
|
| 64 |
-
os.makedirs(os.path.dirname(local_file_path), exist_ok=True)
|
| 65 |
-
download_file(drive_file_path, local_file_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -1,2 +1 @@
|
|
| 1 |
ffmpeg-python
|
| 2 |
-
PyDrive2
|
|
|
|
| 1 |
ffmpeg-python
|
|
|