brynq-sdk-google-drive 1.0.0__tar.gz → 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {brynq_sdk_google_drive-1.0.0 → brynq_sdk_google_drive-2.0.0}/PKG-INFO +1 -1
- {brynq_sdk_google_drive-1.0.0 → brynq_sdk_google_drive-2.0.0}/brynq_sdk_google_drive/google_drive.py +20 -17
- {brynq_sdk_google_drive-1.0.0 → brynq_sdk_google_drive-2.0.0}/brynq_sdk_google_drive.egg-info/PKG-INFO +1 -1
- {brynq_sdk_google_drive-1.0.0 → brynq_sdk_google_drive-2.0.0}/brynq_sdk_google_drive.egg-info/requires.txt +1 -1
- {brynq_sdk_google_drive-1.0.0 → brynq_sdk_google_drive-2.0.0}/setup.py +2 -2
- {brynq_sdk_google_drive-1.0.0 → brynq_sdk_google_drive-2.0.0}/brynq_sdk_google_drive/__init__.py +0 -0
- {brynq_sdk_google_drive-1.0.0 → brynq_sdk_google_drive-2.0.0}/brynq_sdk_google_drive.egg-info/SOURCES.txt +0 -0
- {brynq_sdk_google_drive-1.0.0 → brynq_sdk_google_drive-2.0.0}/brynq_sdk_google_drive.egg-info/dependency_links.txt +0 -0
- {brynq_sdk_google_drive-1.0.0 → brynq_sdk_google_drive-2.0.0}/brynq_sdk_google_drive.egg-info/not-zip-safe +0 -0
- {brynq_sdk_google_drive-1.0.0 → brynq_sdk_google_drive-2.0.0}/brynq_sdk_google_drive.egg-info/top_level.txt +0 -0
- {brynq_sdk_google_drive-1.0.0 → brynq_sdk_google_drive-2.0.0}/setup.cfg +0 -0
{brynq_sdk_google_drive-1.0.0 → brynq_sdk_google_drive-2.0.0}/brynq_sdk_google_drive/google_drive.py
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import os
|
|
2
|
-
from typing import List, Union
|
|
2
|
+
from typing import List, Union, Literal, Optional
|
|
3
3
|
import requests
|
|
4
4
|
import json
|
|
5
5
|
from io import BytesIO
|
|
@@ -9,24 +9,31 @@ from googleapiclient.http import MediaFileUpload
|
|
|
9
9
|
from brynq_sdk_brynq import BrynQ
|
|
10
10
|
|
|
11
11
|
class GoogleDrive(BrynQ):
|
|
12
|
-
def __init__(self,
|
|
12
|
+
def __init__(self, system_type: Optional[Literal['source', 'target']] = None, debug: bool = False):
|
|
13
13
|
"""
|
|
14
14
|
:param label: label of the Google Drive system in BrynQ
|
|
15
15
|
:param debug: set to True to enable debug logging
|
|
16
16
|
"""
|
|
17
17
|
super().__init__()
|
|
18
18
|
api_version = 'v3'
|
|
19
|
+
self.system_type = system_type
|
|
19
20
|
self.base_url = f'https://www.googleapis.com/drive/{api_version}/'
|
|
20
|
-
credentials = self.
|
|
21
|
+
credentials = self.interfaces.credentials.get(system="google-drive", system_type=system_type)
|
|
22
|
+
self.credentials = credentials.get('data')
|
|
21
23
|
self.debug = debug
|
|
22
24
|
if self.debug:
|
|
23
25
|
print(f"credentials: {credentials}")
|
|
24
|
-
self.access_token = credentials['
|
|
25
|
-
self.
|
|
26
|
+
self.access_token = credentials['access_token']
|
|
27
|
+
self.timeout = 3600
|
|
28
|
+
|
|
29
|
+
def _refresh_credentials(self):
|
|
30
|
+
credentials = self.interfaces.credentials.get(system="sharepoint", system_type=self.system_type)
|
|
31
|
+
credentials = credentials.get('data')
|
|
32
|
+
self.access_token = credentials['access_token']
|
|
26
33
|
|
|
27
34
|
def _get_google_drive_headers(self):
|
|
28
|
-
|
|
29
|
-
headers = {'Authorization': f'Bearer {access_token}'}
|
|
35
|
+
self._refresh_credentials()
|
|
36
|
+
headers = {'Authorization': f'Bearer {self.access_token}'}
|
|
30
37
|
if self.debug:
|
|
31
38
|
print(headers)
|
|
32
39
|
return headers
|
|
@@ -45,7 +52,7 @@ class GoogleDrive(BrynQ):
|
|
|
45
52
|
if drive_id:
|
|
46
53
|
params['driveId'] = drive_id
|
|
47
54
|
params['corpora'] = 'drive'
|
|
48
|
-
response = requests.get(url=url, headers=headers, params=params)
|
|
55
|
+
response = requests.get(url=url, headers=headers, params=params, timeout=self.timeout)
|
|
49
56
|
response.raise_for_status()
|
|
50
57
|
return response
|
|
51
58
|
|
|
@@ -55,8 +62,7 @@ class GoogleDrive(BrynQ):
|
|
|
55
62
|
local_file_path: local path of the file you want to upload
|
|
56
63
|
remote_file_path: remote path of the folder and filename where you want to place the file
|
|
57
64
|
"""
|
|
58
|
-
|
|
59
|
-
service = build('drive', 'v3', credentials=credentials)
|
|
65
|
+
service = build('drive', 'v3', credentials=self.credentials)
|
|
60
66
|
|
|
61
67
|
file_metadata = {'name': os.path.basename(remote_file_path)}
|
|
62
68
|
media = MediaFileUpload(local_file_path, resumable=True)
|
|
@@ -81,7 +87,7 @@ class GoogleDrive(BrynQ):
|
|
|
81
87
|
"""
|
|
82
88
|
url = f'{self.base_url}files/{file_id}/export?mimeType={mime_type}'
|
|
83
89
|
headers = self._get_google_drive_headers()
|
|
84
|
-
response = requests.get(url=url, headers=headers)
|
|
90
|
+
response = requests.get(url=url, headers=headers, timeout=self.timeout)
|
|
85
91
|
response.raise_for_status()
|
|
86
92
|
with open(local_file_path, 'wb') as f:
|
|
87
93
|
f.write(response.content)
|
|
@@ -93,8 +99,7 @@ class GoogleDrive(BrynQ):
|
|
|
93
99
|
local_folder_path: local folder where the files will be downloaded to
|
|
94
100
|
remote_folder_path: remote path of the folder you want to get on Google Drive
|
|
95
101
|
"""
|
|
96
|
-
|
|
97
|
-
service = build('drive', 'v3', credentials=credentials)
|
|
102
|
+
service = build('drive', 'v3', credentials=self.credentials)
|
|
98
103
|
|
|
99
104
|
# List files in the specified remote folder
|
|
100
105
|
query = f"'{remote_folder_path}' in parents"
|
|
@@ -129,8 +134,7 @@ class GoogleDrive(BrynQ):
|
|
|
129
134
|
remote_file_path: complete path including filename
|
|
130
135
|
:return: response from Google Drive
|
|
131
136
|
"""
|
|
132
|
-
|
|
133
|
-
service = build('drive', 'v3', credentials=credentials)
|
|
137
|
+
service = build('drive', 'v3', credentials=self.credentials)
|
|
134
138
|
|
|
135
139
|
# Find the file ID
|
|
136
140
|
query = f"name = '{remote_file_path}'"
|
|
@@ -152,8 +156,7 @@ class GoogleDrive(BrynQ):
|
|
|
152
156
|
Remove a folder from Google Drive
|
|
153
157
|
folder: folder id that you want to delete
|
|
154
158
|
"""
|
|
155
|
-
|
|
156
|
-
service = build('drive', 'v3', credentials=credentials)
|
|
159
|
+
service = build('drive', 'v3', credentials=self.credentials)
|
|
157
160
|
|
|
158
161
|
response = service.files().delete(fileId=folder_id).execute()
|
|
159
162
|
if self.debug:
|
|
@@ -2,7 +2,7 @@ from setuptools import setup, find_namespace_packages
|
|
|
2
2
|
|
|
3
3
|
setup(
|
|
4
4
|
name='brynq_sdk_google_drive',
|
|
5
|
-
version='
|
|
5
|
+
version='2.0.0',
|
|
6
6
|
description='Google Drive wrapper from BrynQ',
|
|
7
7
|
long_description='Groogle Drive wrapper from BrynQ',
|
|
8
8
|
author='BrynQ',
|
|
@@ -10,7 +10,7 @@ setup(
|
|
|
10
10
|
packages=find_namespace_packages(include=['brynq_sdk*']),
|
|
11
11
|
license='BrynQ License',
|
|
12
12
|
install_requires=[
|
|
13
|
-
'brynq-sdk-brynq>=
|
|
13
|
+
'brynq-sdk-brynq>=4,<5',
|
|
14
14
|
'google-api-python-client>=2,<3',
|
|
15
15
|
'requests>=2,<=3'
|
|
16
16
|
],
|
{brynq_sdk_google_drive-1.0.0 → brynq_sdk_google_drive-2.0.0}/brynq_sdk_google_drive/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|