Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5ac1c9d
test setting a variable from action
flufflycthu1u Apr 8, 2026
e90427f
Experiment with database options
flufflycthu1u Apr 8, 2026
21c879b
Add database artifact logic to dev action and main workflow
flufflycthu1u May 13, 2026
c4c0818
Continue action if previous run can't be identified
flufflycthu1u May 13, 2026
cb7b239
Initialize correct variable
flufflycthu1u May 13, 2026
e32941f
Add timezone arg to cutoff date
flufflycthu1u May 13, 2026
839b93c
Try displaying the selected pet
flufflycthu1u May 13, 2026
ae900b4
Add pet_id field to debug source
flufflycthu1u May 13, 2026
237c982
Remove experimental action and script
flufflycthu1u May 20, 2026
05aae2e
Experiment with database options
flufflycthu1u Apr 8, 2026
1294950
Add database artifact logic to dev action and main workflow
flufflycthu1u May 13, 2026
5a500a1
Revert fix to move to new branch
flufflycthu1u May 13, 2026
e55031d
Continue action if previous run can't be identified
flufflycthu1u May 13, 2026
1f368c1
Initialize correct variable
flufflycthu1u May 13, 2026
724d5e0
Add timezone arg to cutoff date
flufflycthu1u May 13, 2026
df12fa2
test pet id
flufflycthu1u May 13, 2026
ae653ca
Try displaying the selected pet
flufflycthu1u May 13, 2026
1120d9c
Remove experimental action and script
flufflycthu1u May 20, 2026
4f7d3a9
Fix line endings
flufflycthu1u May 20, 2026
ba31cd3
Fix json reading and only use current branch db
flufflycthu1u May 20, 2026
b3ea665
Add database logic to prod action
flufflycthu1u May 20, 2026
bbc5f9f
Delete dev artifacts faster to reduce chance of running out of pets
flufflycthu1u May 20, 2026
3f7ae98
Fix action permissions
flufflycthu1u May 20, 2026
aa21e2a
Exit with error when no elligible pets are found
flufflycthu1u May 21, 2026
b0ab319
Revert test change
flufflycthu1u May 21, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
- '!master'
workflow_dispatch:

permissions:
actions: read

jobs:
run-cute-pets:
runs-on: ubuntu-latest
Expand All @@ -22,6 +25,30 @@ jobs:
- name: Install dependencies
run: pip install --break-system-packages -r requirements.txt

- name: Get Previous Run ID
continue-on-error: true
id: get_id
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Fetches the ID of the last completed run for the current workflow
PREVIOUS_RUN_ID=$(gh run list \
--branch "${{ github.ref_name }}" \
--workflow "${{ github.workflow }}" \
--status success \
--limit 1 \
--json databaseId \
--jq '.[0].databaseId')
echo "previous_run_id=$PREVIOUS_RUN_ID" >> "$GITHUB_OUTPUT"

- name: Download previous database artifact
uses: actions/download-artifact@v8
with:
name: database.json
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ steps.get_id.outputs.previous_run_id }}
continue-on-error: true

- name: Call RescueGroups API
env:
CUTEPETSBOSTON_RESCUEGROUPS_API_KEY: ${{ secrets.CUTEPETSBOSTON_RESCUEGROUPS_API_KEY }}
Expand All @@ -34,3 +61,10 @@ jobs:
run: |
#In order to create posts on the test accounts remove the --debugposters debug flag
python ./main.py --debugsources --debugposters

- name: Upload database artifact
uses: actions/upload-artifact@v7
with:
path: database.json
retention-days: 1
archive: false
34 changes: 34 additions & 0 deletions .github/workflows/prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
# Every 4 hours
- cron: "0 */4 * * *"

permissions:
actions: read

jobs:
run-cute-pets:
runs-on: ubuntu-latest
Expand All @@ -21,6 +24,30 @@ jobs:
- name: Install dependencies
run: pip install --break-system-packages -r requirements.txt

- name: Get Previous Run ID
continue-on-error: true
id: get_id
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Fetches the ID of the last completed run for the current workflow
PREVIOUS_RUN_ID=$(gh run list \
--branch "${{ github.ref_name }}" \
--workflow "${{ github.workflow }}" \
--status success \
--limit 1 \
--json databaseId \
--jq '.[0].databaseId')
echo "previous_run_id=$PREVIOUS_RUN_ID" >> "$GITHUB_OUTPUT"

- name: Download previous database artifact
uses: actions/download-artifact@v8
with:
name: database.json
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ steps.get_id.outputs.previous_run_id }}
continue-on-error: true

- name: Call RescueGroups API
env:
CUTEPETSBOSTON_RESCUEGROUPS_API_KEY: ${{ secrets.CUTEPETSBOSTON_RESCUEGROUPS_API_KEY }}
Expand All @@ -32,3 +59,10 @@ jobs:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
APP_ENV: prod
run: python ./main.py

- name: Upload database artifact
uses: actions/upload-artifact@v7
with:
path: database.json
retention-days: 14
archive: false
2 changes: 2 additions & 0 deletions adoption_sources/manual.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def fetch_pets(self) -> Iterable[AdoptablePet]:

def _build_pet(self, animal: dict) -> AdoptablePet:
attrs = animal.get("attributes", {})
animal_id = animal.get("id", "")
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manual.py could probably use some updating. The pet object it was creating didn't have the pet_id we should check if anything else is missing.

return AdoptablePet(
name=attrs.get("name", "Unknown"),
species=self.species,
Expand All @@ -44,6 +45,7 @@ def _build_pet(self, animal: dict) -> AdoptablePet:
description=(attrs.get("descriptionText") or "").strip(),
adoption_url=self._adoption_url(attrs.get("slug")),
image_url=attrs.get("pictureThumbnailUrl"),
pet_id=animal_id,
)

@staticmethod
Expand Down
42 changes: 38 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import os
import random
import argparse
import json
import sys
import traceback
from pathlib import Path
from datetime import datetime, timezone, timedelta

import requests

Expand Down Expand Up @@ -87,10 +91,40 @@ def run(sources, posters):


def pick_pet(pets):
eligible = [pet for pet in pets if pet.image_url and pet.adoption_url]
if not eligible:
return None
return random.choice(eligible)
Path("database.json").touch(exist_ok=True)
# Open file
with open("database.json", "r+") as f:
# Load json
try:
data = json.load(f)
except (json.JSONDecodeError, ValueError) as e:
print(f"{type(e).__name__}:{e}", file=sys.stderr)
traceback.print_exc()
data = {}

if "posted_pets" in data:
posted_pet_ids = {posted_pet["pet_id"] for posted_pet in data["posted_pets"]}
else:
posted_pet_ids = {}
data["posted_pets"] = []
# Check pet has an image, adoption url, and has not been posted
eligible = [pet for pet in pets if pet.image_url and pet.adoption_url and pet.pet_id not in posted_pet_ids]
if not eligible:
sys.exit("Error: No elligible pets found.")
return None

selected_pet = random.choice(eligible)
# Add pet ID to list of posted pets
data["posted_pets"].append({"name": selected_pet.name, "pet_id": selected_pet.pet_id, "time": datetime.now(timezone.utc).isoformat()})
# Remove old pets
cutoff = datetime.now(timezone.utc) - timedelta(weeks=12)
recent_pets = [item for item in data["posted_pets"] if datetime.fromisoformat(item['time']) > cutoff]
data["posted_pets"] = recent_pets
# Export json
f.seek(0)
json.dump(data, f, indent=4)
f.truncate()
return selected_pet


# Slack incoming-webhook messages have a ~40k-char limit; cap the traceback
Expand Down
Loading