Spaces:
Running
Running
Update pipeline.py
Browse files- pipeline.py +32 -6
pipeline.py
CHANGED
@@ -49,17 +49,43 @@ def get_or_create_drive_folder(name, parent_id=None):
|
|
49 |
file_metadata["parents"] = [parent_id]
|
50 |
file = drive_service.files().create(body=file_metadata, fields="id").execute()
|
51 |
return file["id"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
def find_drive_file(filename, parent_id):
|
53 |
"""
|
54 |
Checks if a file with the given name exists inside the specified Google Drive folder.
|
55 |
Returns the file ID if found, else None.
|
56 |
"""
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
|
65 |
# def upload_file_to_drive(local_path, remote_name, folder_id):
|
|
|
49 |
file_metadata["parents"] = [parent_id]
|
50 |
file = drive_service.files().create(body=file_metadata, fields="id").execute()
|
51 |
return file["id"]
|
52 |
+
# def find_drive_file(filename, parent_id):
|
53 |
+
# """
|
54 |
+
# Checks if a file with the given name exists inside the specified Google Drive folder.
|
55 |
+
# Returns the file ID if found, else None.
|
56 |
+
# """
|
57 |
+
# query = f"'{parent_id}' in parents and name = '{filename}' and trashed = false"
|
58 |
+
# results = drive_service.files().list(q=query, spaces='drive', fields='files(id, name)', pageSize=1).execute()
|
59 |
+
# files = results.get('files', [])
|
60 |
+
# if files:
|
61 |
+
# return files[0]["id"]
|
62 |
+
# return None
|
63 |
+
|
64 |
def find_drive_file(filename, parent_id):
|
65 |
"""
|
66 |
Checks if a file with the given name exists inside the specified Google Drive folder.
|
67 |
Returns the file ID if found, else None.
|
68 |
"""
|
69 |
+
try:
|
70 |
+
print(f"🔍 Searching for '{filename}' in folder: {parent_id}")
|
71 |
+
query = f"'{parent_id}' in parents and name = '{filename}' and trashed = false"
|
72 |
+
results = drive_service.files().list(
|
73 |
+
q=query,
|
74 |
+
spaces='drive',
|
75 |
+
fields='files(id, name)',
|
76 |
+
pageSize=1
|
77 |
+
).execute()
|
78 |
+
files = results.get('files', [])
|
79 |
+
if files:
|
80 |
+
print(f"✅ Found file: {files[0]['name']} with ID: {files[0]['id']}")
|
81 |
+
return files[0]["id"]
|
82 |
+
else:
|
83 |
+
print("⚠️ File not found.")
|
84 |
+
return None
|
85 |
+
except Exception as e:
|
86 |
+
print(f"❌ Error during find_drive_file: {e}")
|
87 |
+
return None
|
88 |
+
|
89 |
|
90 |
|
91 |
# def upload_file_to_drive(local_path, remote_name, folder_id):
|