Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,7 +17,7 @@ drive_service = build('drive', 'v3', credentials=credentials)
|
|
| 17 |
|
| 18 |
# Salesforce Authentication
|
| 19 |
sf = Salesforce(
|
| 20 |
-
username='
|
| 21 |
password='Mahadev@9',
|
| 22 |
security_token='q67QF1yG0qBTSaiEfDrRrIEx',
|
| 23 |
domain='login'
|
|
@@ -37,7 +37,7 @@ def get_all_salesforce_files(custom_object_api_name):
|
|
| 37 |
|
| 38 |
# Step 2: Loop through each record ID and get linked files
|
| 39 |
for record_id in record_ids:
|
| 40 |
-
query_files = f"SELECT Id,
|
| 41 |
results = sf.query(query_files)
|
| 42 |
|
| 43 |
if results['records']:
|
|
@@ -63,9 +63,19 @@ def save_salesforce_files(custom_object_api_name):
|
|
| 63 |
files = get_all_salesforce_files(custom_object_api_name)
|
| 64 |
for file in files:
|
| 65 |
content_doc_id = file['ContentDocumentId']
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
print(f"Downloading file {google_drive_file_name} from Google Drive...")
|
| 70 |
file_path = download_google_drive_file(google_drive_id, google_drive_file_name)
|
| 71 |
if os.path.exists(file_path):
|
|
@@ -77,4 +87,3 @@ if __name__ == "__main__":
|
|
| 77 |
# Replace 'YOUR_CUSTOM_OBJECT_API_NAME' with the Salesforce custom object API name
|
| 78 |
custom_object_api_name = 'CustomerInfo__c'
|
| 79 |
save_salesforce_files(custom_object_api_name)
|
| 80 |
-
|
|
|
|
| 17 |
|
| 18 |
# Salesforce Authentication
|
| 19 |
sf = Salesforce(
|
| 20 |
+
username='bharatmali@sathkrutha.com',
|
| 21 |
password='Mahadev@9',
|
| 22 |
security_token='q67QF1yG0qBTSaiEfDrRrIEx',
|
| 23 |
domain='login'
|
|
|
|
| 37 |
|
| 38 |
# Step 2: Loop through each record ID and get linked files
|
| 39 |
for record_id in record_ids:
|
| 40 |
+
query_files = f"SELECT Id, ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = '{record_id}'"
|
| 41 |
results = sf.query(query_files)
|
| 42 |
|
| 43 |
if results['records']:
|
|
|
|
| 63 |
files = get_all_salesforce_files(custom_object_api_name)
|
| 64 |
for file in files:
|
| 65 |
content_doc_id = file['ContentDocumentId']
|
| 66 |
+
|
| 67 |
+
# Query ContentDocument to get the Title
|
| 68 |
+
content_doc_query = f"SELECT Title, FileExtension FROM ContentDocument WHERE Id = '{content_doc_id}'"
|
| 69 |
+
content_doc_result = sf.query(content_doc_query)
|
| 70 |
+
|
| 71 |
+
if not content_doc_result['records']:
|
| 72 |
+
print(f"No details found for ContentDocumentId: {content_doc_id}")
|
| 73 |
+
continue
|
| 74 |
+
|
| 75 |
+
content_doc = content_doc_result['records'][0]
|
| 76 |
+
google_drive_id = content_doc_id # Assuming ContentDocumentId is the Google Drive file ID
|
| 77 |
+
google_drive_file_name = content_doc['Title'] + '.' + content_doc['FileExtension'] # Use Title and FileExtension
|
| 78 |
+
|
| 79 |
print(f"Downloading file {google_drive_file_name} from Google Drive...")
|
| 80 |
file_path = download_google_drive_file(google_drive_id, google_drive_file_name)
|
| 81 |
if os.path.exists(file_path):
|
|
|
|
| 87 |
# Replace 'YOUR_CUSTOM_OBJECT_API_NAME' with the Salesforce custom object API name
|
| 88 |
custom_object_api_name = 'CustomerInfo__c'
|
| 89 |
save_salesforce_files(custom_object_api_name)
|
|
|