Skip to content

Commit

Permalink
Merge pull request #138 from mongulu-cm/docstring
Browse files Browse the repository at this point in the history
Docstring
  • Loading branch information
Joyce-Tchamdjou authored Aug 7, 2023
2 parents 59d57f2 + 8d0df38 commit 6711992
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 27 deletions.
6 changes: 4 additions & 2 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tasks:
- init: |
- init: |
pip install -r requirements.txt && pip install -r api/requirements.txt
pre-commit install
command: |
Expand All @@ -8,4 +8,6 @@ tasks:
vscode:
extensions:
- vivaxy.vscode-conventional-commits
- vivaxy.vscode-conventional-commits
- sourcegraph.cody-ai
- donjayamanne.githistory
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ repos:
rev: 22.6.0
hooks:
- id: black
language_version: python3.8
language_version: python3
- repo: https://github.com/Yelp/detect-secrets
rev: v1.3.0
hooks:
- id: detect-secrets
name: Detect secrets
language: python
entry: detect-secrets-hook
args: ['--baseline', '.secrets.baseline']
args: ['--baseline', '.secrets.baseline']
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ If you are here, it means that you are interested in an in-house deployment of t
### Prerequisites

* Have a minimum of competence on the AWS and Terraform cloud
* Create a Sourcegraph account and get credentials to use [CodyAI](https://www.youtube.com/watch?v=_csyHcEcxDA)
* Install all tools locally (just run the `init` and `command` scripts in the [.gitpod.yml] file (.gitpod.yml) **or** use a ready-made development environment on gitpod :

[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/mongulu-cm/mtchoun-mouh)
Expand Down
76 changes: 53 additions & 23 deletions infra/api/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@


def Images_in_Bucket(Bucket_Name):
"""
This function takes in a bucket name and returns a list of all the images in that bucket
"""Gets a list of all image names in an S3 bucket.
Args:
Bucket_Name (str): The name of the S3 bucket
:param Bucket_Name: The name of the bucket you want to list the images from
:return: A list of all the images in the bucket.
Returns:
list: A list containing all the image names in the given S3 bucket
"""
s3 = client("s3")
Image_List = []
Expand All @@ -23,33 +25,58 @@ def Images_in_Bucket(Bucket_Name):


def Empty_Bucket(Bucket_Name):
"""
It takes a bucket name as an argument, and then deletes all the objects in that bucket.
"""Deletes all objects in an S3 bucket.
This function takes the name of an S3 bucket, connects to the S3 service
using boto3, gets a bucket resource object for the specified bucket,
and calls delete() on all objects in the bucket to empty it.
Args:
Bucket_Name (str): The name of the S3 bucket to empty
Returns:
None
Raises:
Any exceptions raised by boto3 calls
:param Bucket_Name: The name of the bucket you want to empty
"""
s3 = boto3.resource("s3")
bucket = s3.Bucket(Bucket_Name)
bucket.objects.all().delete()


def Delete_Image(Bucket_Name, ImageName):
"""
This function deletes an image from an S3 bucket
"""Deletes an image from an S3 bucket.
Args:
Bucket_Name (str): The name of the S3 bucket.
ImageName (str): The key name of the image file to delete.
Returns:
None
Raises:
Any exceptions raised by boto3 delete_object call.
:param Bucket_Name: The name of the bucket you want to upload the image to
:param ImageName: The name of the image you want to delete
"""
s3 = client("s3")
s3.delete_object(Bucket=Bucket_Name, Key=ImageName)


def insert_dynamodb(User, ImageName):
"""
> It takes the user name and the image name as input, and then it inserts a new item into the DynamoDB table
"""Inserts a new item into a DynamoDB table.
Args:
User (str): The user name of the person who uploaded the image.
ImageName (str): The name of the image that was uploaded to S3.
Returns:
None
Raises:
Any exceptions raised by boto3 put_item call.
:param User: The user name of the person who uploaded the image
:param ImageName: The name of the image that was uploaded to S3
"""
region = os.environ["REGION"]
Table_Users = os.environ["USERS_TABLE"]
Expand All @@ -61,12 +88,14 @@ def insert_dynamodb(User, ImageName):


def Extract_Users(s3BucketName, ImageName): # sourcery no-metrics
"""
It takes an image name and an S3 bucket name as input, and then uses Amazon Textract to extract the names of the people
in the image
"""Extracts user information from an image in an S3 bucket.
Args:
s3BucketName (str): The name of the S3 bucket containing the image.
ImageName (str): The name of the image file in the S3 bucket.
:param s3BucketName: The name of the S3 bucket that contains the image
:param ImageName: The name of the image file that you want to extract text from
Returns:
list: A list of extracted user information dicts.
"""
region = os.environ["REGION"]
textract = boto3.client("textract", region_name=region)
Expand Down Expand Up @@ -162,10 +191,11 @@ def Extract_Users(s3BucketName, ImageName): # sourcery no-metrics

def extract_names_from_images():
"""
> It takes all the images in the bucket, extracts the names of the people in the images, and then deletes the images
from the bucket
"""
Extracts names from images using OCR.
Returns:
list: A list of names extracted from the images.
"""
zulip_client = zulip.Client(
email="errorbot-bot@mongulu.zulipchat.com",
api_key=os.environ["API_KEY"],
Expand Down

0 comments on commit 6711992

Please sign in to comment.