Ajay98 commited on
Commit
1ac81f1
·
verified ·
1 Parent(s): 68a28e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +95 -36
app.py CHANGED
@@ -1,36 +1,95 @@
1
- from simple_salesforce import Salesforce, SalesforceMalformedRequest, SalesforceResourceNotFound
2
-
3
- # Replace these variables with your Salesforce credentials
4
- USERNAME = 'alwaysajay411@gmail.com'
5
- PASSWORD = 'Anusha@310819'
6
- SECURITY_TOKEN = 'DcroeUKt0Lc4Lpqgzh9dMxEyQ'
7
-
8
- # Create a connection to Salesforce
9
- try:
10
- sf = Salesforce(username=USERNAME, password=PASSWORD, security_token=SECURITY_TOKEN)
11
-
12
- # Define your custom object API names (replace with your actual custom object API names)
13
- custom_object_1 = 'staff__c'
14
- custom_object_2 = 'CustomerData__c'
15
-
16
- # Retrieve records from the first custom object
17
- records_custom_object_1 = sf.query(f"SELECT Name, AdhardCard__c, contactNumber__c, pancard__c FROM {custom_object_1}")
18
-
19
- # Retrieve records from the second custom object
20
- records_custom_object_2 = sf.query(f"SELECT Name, AdhardCardPhoto__c, pancardPhoto__c, PhoneNumber__c FROM {custom_object_2}")
21
-
22
- # Print retrieved records
23
- print("Records from Custom Object 1:")
24
- for record in records_custom_object_1['records']:
25
- print(record)
26
-
27
- print("\nRecords from Custom Object 2:")
28
- for record in records_custom_object_2['records']:
29
- print(record)
30
-
31
- except SalesforceMalformedRequest as e:
32
- print(f"Malformed request: {e}")
33
- except SalesforceResourceNotFound as e:
34
- print(f"Resource not found: {e}")
35
- except Exception as e:
36
- print(f"An error occurred: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import face_recognition
3
+ import cv2
4
+ import smtplib
5
+ from simple_salesforce import Salesforce
6
+ from email.mime.text import MIMEText
7
+ from email.mime.multipart import MIMEMultipart
8
+
9
+ # Salesforce credentials
10
+ USERNAME = 'your_salesforce_username'
11
+ PASSWORD = 'your_salesforce_password'
12
+ SECURITY_TOKEN = 'your_salesforce_security_token'
13
+
14
+ # Connect to Salesforce
15
+ sf = Salesforce(username=USERNAME, password=PASSWORD, security_token=SECURITY_TOKEN)
16
+
17
+ # Query records from two custom objects (with image fields)
18
+ custom_object_1 = 'CustomObject1__c'
19
+ custom_object_2 = 'CustomObject2__c'
20
+
21
+ # Replace with actual field names
22
+ query_1 = f"SELECT Id, Name, PhotoField__c FROM {custom_object_1}"
23
+ query_2 = f"SELECT Id, Name, PhotoField__c FROM {custom_object_2}"
24
+
25
+ # Retrieve records
26
+ records_custom_object_1 = sf.query(query_1)['records']
27
+ records_custom_object_2 = sf.query(query_2)['records']
28
+
29
+ # Combine both objects' records
30
+ salesforce_records = records_custom_object_1 + records_custom_object_2
31
+
32
+ # Function to send an email if unknown face is found
33
+ def send_email(unknown_image_path):
34
+ sender_email = "your_email@gmail.com"
35
+ receiver_email = "receiver_email@gmail.com"
36
+ password = "your_email_password"
37
+
38
+ message = MIMEMultipart("alternative")
39
+ message["Subject"] = "Unknown Face Detected"
40
+ message["From"] = sender_email
41
+ message["To"] = receiver_email
42
+
43
+ # Email body
44
+ text = f"An unknown face was detected in the image: {unknown_image_path}"
45
+ part1 = MIMEText(text, "plain")
46
+ message.attach(part1)
47
+
48
+ # Send email
49
+ with smtplib.SMTP_SSL("smtp.gmail.com", 465) as server:
50
+ server.login(sender_email, password)
51
+ server.sendmail(sender_email, receiver_email, message.as_string())
52
+
53
+ # Folder with input images to match
54
+ input_folder = "path_to_input_images_folder"
55
+
56
+ # Function to compare images and find matches
57
+ def compare_images(salesforce_records, input_folder):
58
+ for image_file in os.listdir(input_folder):
59
+ input_image_path = os.path.join(input_folder, image_file)
60
+
61
+ # Load the input image
62
+ input_image = face_recognition.load_image_file(input_image_path)
63
+ input_encoding = face_recognition.face_encodings(input_image)
64
+
65
+ if len(input_encoding) == 0:
66
+ print(f"No face found in {image_file}")
67
+ continue
68
+
69
+ input_encoding = input_encoding[0]
70
+
71
+ found_match = False
72
+
73
+ # Compare input image to Salesforce records
74
+ for record in salesforce_records:
75
+ record_photo_url = record['PhotoField__c']
76
+
77
+ # Load Salesforce image (you can download and use images from Salesforce as needed)
78
+ # Here, assuming the photos are locally available
79
+ salesforce_image = face_recognition.load_image_file(record_photo_url)
80
+ salesforce_encoding = face_recognition.face_encodings(salesforce_image)[0]
81
+
82
+ # Compare the encodings
83
+ matches = face_recognition.compare_faces([salesforce_encoding], input_encoding)
84
+
85
+ if True in matches:
86
+ print(f"Match found! Input image matches {record['Name']}")
87
+ found_match = True
88
+ break
89
+
90
+ if not found_match:
91
+ print(f"Unknown face in {image_file}")
92
+ send_email(input_image_path)
93
+
94
+ # Run the comparison function
95
+ compare_images(salesforce_records, input_folder)