AbderrahmanSkiredj1 commited on
Commit
ac37a5f
·
verified ·
1 Parent(s): f115bda

Create fetch.py

Browse files
Files changed (1) hide show
  1. fetch.py +41 -0
fetch.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from google.oauth2 import service_account
2
+ from googleapiclient.discovery import build
3
+ from googleapiclient.http import MediaIoBaseDownload
4
+ import io
5
+ import os
6
+
7
+
8
+ def download_file(file_id, file_name):
9
+ # Load the credentials from environment variables
10
+ creds_info = {
11
+ "type": "service_account",
12
+ "project_id": os.environ.get('GCP_PROJECT_ID'),
13
+ "private_key_id": os.environ.get('GCP_PRIVATE_KEY_ID'),
14
+ "private_key": os.environ.get('GCP_PRIVATE_KEY').replace('\\n', '\n'),
15
+ "client_email": os.environ.get('GCP_CLIENT_EMAIL'),
16
+ "client_id": os.environ.get('GCP_CLIENT_ID'),
17
+ "auth_uri": "https://accounts.google.com/o/oauth2/auth",
18
+ "token_uri": "https://oauth2.googleapis.com/token",
19
+ "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
20
+ "client_x509_cert_url": os.environ.get('GCP_CLIENT_X509_CERT_URL'),
21
+ "universe_domain": "googleapis.com"
22
+ }
23
+
24
+ creds = service_account.Credentials.from_service_account_info(creds_info)
25
+
26
+ # Build the service
27
+ drive_service = build('drive', 'v3', credentials=creds)
28
+
29
+ request = drive_service.files().get_media(fileId=file_id)
30
+ fh = io.FileIO(file_name, 'wb')
31
+ downloader = MediaIoBaseDownload(fh, request)
32
+ done = False
33
+ while done is False:
34
+ status, done = downloader.next_chunk()
35
+ print(f'Download {int(status.progress() * 100)}%.')
36
+
37
+
38
+ if __name__ == '__main__':
39
+ # Replace 'your_file_id' with the actual file ID of your zip file on Google Drive
40
+ download_file(os.environ.get("CODE_URL"), 'code.zip')
41
+