Note - Double Click to Copy Code Contact Us!

Attendance-Tracking-System-using-cloud-computing using Python

Tech Doubility
Attendance-Tracking-System-using-cloud-computing using Python

  1. import boto3
  2. import datetime
  3.  
  4. # Initialize AWS clients
  5. dynamodb = boto3.client('dynamodb')
  6. rekognition = boto3.client('rekognition')
  7.  
  8. # Name of the DynamoDB table
  9. table_name = 'AttendanceTable'
  10.  
  11. def create_table():
  12. # Create a DynamoDB table to store attendance records
  13. table = dynamodb.create_table(
  14. TableName=table_name,
  15. KeySchema=[
  16. {
  17. 'AttributeName': 'StudentID',
  18. 'KeyType': 'HASH' # Partition key
  19. },
  20. {
  21. 'AttributeName': 'Timestamp',
  22. 'KeyType': 'RANGE' # Sort key
  23. }
  24. ],
  25. AttributeDefinitions=[
  26. {
  27. 'AttributeName': 'StudentID',
  28. 'AttributeType': 'S'
  29. },
  30. {
  31. 'AttributeName': 'Timestamp',
  32. 'AttributeType': 'N'
  33. }
  34. ],
  35. ProvisionedThroughput={
  36. 'ReadCapacityUnits': 5,
  37. 'WriteCapacityUnits': 5
  38. }
  39. )
  40.  
  41. # Wait for the table to be created
  42. dynamodb.get_waiter('table_exists').wait(TableName=table_name)
  43. print('Table created:', table_name)
  44.  
  45. def detect_faces(image):
  46. # Use AWS Rekognition to detect faces in an image
  47. response = rekognition.detect_faces(
  48. Image={'Bytes': image},
  49. Attributes=['DEFAULT']
  50. )
  51. return response['FaceDetails']
  52.  
  53. def process_image(image):
  54. # Process an image and detect faces
  55. faces = detect_faces(image)
  56.  
  57. # Identify each face and store attendance records
  58. for face in faces:
  59. face_id = face['FaceId']
  60. student_id = input('Enter student ID: ') # Prompt for student ID (you can modify this)
  61. timestamp = int(datetime.datetime.now().timestamp())
  62.  
  63. # Store attendance record in DynamoDB
  64. dynamodb.put_item(
  65. TableName=table_name,
  66. Item={
  67. 'StudentID': {'S': student_id},
  68. 'Timestamp': {'N': str(timestamp)},
  69. 'FaceID': {'S': face_id}
  70. }
  71. )
  72. print('Attendance recorded for student ID:', student_id)
  73.  
  74. # Main program
  75. def main():
  76. create_table()
  77. # Assuming you have an image named 'attendance.jpg' in the current directory
  78. with open('attendance.jpg', 'rb') as image_file:
  79. image = image_file.read()
  80. process_image(image)
  81.  
  82. if __name__ == '__main__':
  83. main()

In this example, we are using the AWS SDK for Python (Boto3) to interact with Amazon DynamoDB for storing attendance records and Amazon Rekognition for face detection. The code first creates a DynamoDB table to store the attendance records. Then it uses Rekognition to detect faces in an image and prompts for the student ID associated with each face. Finally, it stores the attendance record in DynamoDB.

Please make sure to install the required dependencies (boto3) and configure your AWS credentials before running the code. Also, note that you need to have an AWS account and the necessary permissions to create DynamoDB tables and use Rekognition services.

Remember to customize the code according to your specific requirements, such as modifying the table schema, handling errors, and integrating with other components of your attendance tracking system.

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.