Bhargav3000 commited on
Commit
99e4c12
·
verified ·
1 Parent(s): 1d8b746

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -12
app.py CHANGED
@@ -17,7 +17,7 @@ drive_service = build('drive', 'v3', credentials=credentials)
17
 
18
  # Salesforce Authentication
19
  sf = Salesforce(
20
- username='bharat@sathkrutha.sandbox',
21
  password='Mahadev@9',
22
  security_token='q67QF1yG0qBTSaiEfDrRrIEx',
23
  domain='login'
@@ -35,7 +35,7 @@ def get_all_salesforce_files(custom_object_api_name):
35
 
36
  all_files = []
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)
@@ -64,7 +64,7 @@ def save_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
 
@@ -73,17 +73,20 @@ def save_salesforce_files(custom_object_api_name):
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):
82
- print(f"File {google_drive_file_name} saved successfully to {file_path}")
83
- else:
84
- print(f"Failed to save file {google_drive_file_name}")
 
 
 
 
85
 
86
  if __name__ == "__main__":
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)
 
17
 
18
  # Salesforce Authentication
19
  sf = Salesforce(
20
+ username='bharatmali@sathkrutha.com',
21
  password='Mahadev@9',
22
  security_token='q67QF1yG0qBTSaiEfDrRrIEx',
23
  domain='login'
 
35
 
36
  all_files = []
37
 
38
+ # Step 2: Loop through each record ID and get linked files from the Files object
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)
 
64
  for file in files:
65
  content_doc_id = file['ContentDocumentId']
66
 
67
+ # Query ContentDocument to get the Title and FileExtension
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
 
 
73
  continue
74
 
75
  content_doc = content_doc_result['records'][0]
76
+ file_name = content_doc['Title'] + '.' + content_doc['FileExtension']
 
77
 
78
+ # Download the file from Google Drive using the ContentDocument ID (assuming the file is stored in Google Drive)
79
+ try:
80
+ print(f"Downloading file {file_name} from Google Drive...")
81
+ file_path = download_google_drive_file(content_doc_id, file_name)
82
+ if os.path.exists(file_path):
83
+ print(f"File {file_name} saved successfully to {file_path}")
84
+ else:
85
+ print(f"Failed to save file {file_name}")
86
+ except Exception as e:
87
+ print(f"Error downloading file {file_name}: {e}")
88
 
89
  if __name__ == "__main__":
90
  # Replace 'YOUR_CUSTOM_OBJECT_API_NAME' with the Salesforce custom object API name
91
+ custom_object_api_name = 'YOUR_CUSTOM_OBJECT_API_NAME'
92
  save_salesforce_files(custom_object_api_name)