Skip to content

Commit

Permalink
refactor: remove dupe code
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacHooper committed Feb 29, 2024
1 parent f808891 commit e6f2d61
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions api/utils/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def upload_review(review: dict, bucket: str) -> bool:
return False


def get_active_coffees(bucket: str) -> list[dict]:
def get_all_coffees(bucket: str) -> list[dict]:
"""Get the active coffees from S3"""
s3 = boto3.client("s3")
key = "coffees.json"
Expand All @@ -24,22 +24,14 @@ def get_active_coffees(bucket: str) -> list[dict]:

# Load the JSON
all_coffees = json.loads(all_coffees_raw["Body"].read())

# Filter for active coffees
active_coffees = [coffee for coffee in all_coffees if coffee["active"]]
return active_coffees
return all_coffees


def get_all_coffees(bucket: str) -> list[dict]:
def get_active_coffees(bucket: str) -> list[dict]:
"""Get the active coffees from S3"""
s3 = boto3.client("s3")
key = "coffees.json"
# Download the coffees.json file
all_coffees_raw = s3.get_object(Bucket=bucket, Key=key)

# Load the JSON
all_coffees = json.loads(all_coffees_raw["Body"].read())
return all_coffees
all_coffees = get_all_coffees(bucket)
active_coffees = [coffee for coffee in all_coffees if coffee["active"]]
return active_coffees


def update_coffees(coffees: list[dict], bucket: str) -> bool:
Expand Down

0 comments on commit e6f2d61

Please sign in to comment.