Skip to content

Commit 9445457

Browse files
authored
Merge pull request #89 from codeforboston/refactor/configurable-city-config
Platform location config
2 parents 35451b4 + 870edcd commit 9445457

5 files changed

Lines changed: 15 additions & 6 deletions

File tree

abstractions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from dataclasses import dataclass, field
33
from typing import Iterable
44

5+
from config import CITY_NAME, CITY_STATE
6+
57

68
# =============================================================================
79
# Pet Ingestor Interface
@@ -120,7 +122,7 @@ def format_post(self, pet: AdoptablePet) -> Post:
120122
text += f"\n\nAdopt {pet.name}: {pet.adoption_url}"
121123

122124
city = ""
123-
if pet.location != "Boston, MA":
125+
if pet.location != f"{CITY_NAME}, {CITY_STATE}":
124126
city = pet.location.split(",")[0].capitalize()
125127

126128
return Post(

adoption_sources/manual.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import Iterable, Sequence
77

88
from abstractions import AdoptablePet, PetSource
9+
from config import CITY_NAME, CITY_STATE
910

1011
_data_path = __file__.replace(".py", ".json")
1112
with open(_data_path) as _f:
@@ -18,7 +19,7 @@ class SourceManual(PetSource):
1819
def __init__(
1920
self,
2021
animals: Sequence[dict] | None = None,
21-
location_label: str = "Boston, MA",
22+
location_label: str = f"{CITY_NAME}, {CITY_STATE}",
2223
species: str = "dog",
2324
) -> None:
2425
self._animals: Sequence[dict] = animals if animals is not None else MANUAL_SOURCE_DATA

adoption_sources/rescue_groups.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import requests
1515

1616
from abstractions import AdoptablePet, PetSource
17+
from config import CITY_NAME, CITY_STATE, POSTAL_CODE
1718

1819
logger = logging.getLogger(__name__)
1920

@@ -30,11 +31,11 @@ class SourceRescueGroups(PetSource):
3031
def __init__(
3132
self,
3233
api_key: str | None = None,
33-
postal_code: str = "02108", # Boston
34+
postal_code: str = POSTAL_CODE,
3435
radius_miles: int = 50,
3536
species: str = "dogs", # "dogs" or "cats"
3637
limit: int = 25,
37-
location_label: str = "Boston, MA", # For display purposes
38+
location_label: str = f"{CITY_NAME}, {CITY_STATE}",
3839
):
3940
self._api_key = api_key or os.environ.get("CUTEPETSBOSTON_RESCUEGROUPS_API_KEY")
4041
self.postal_code = postal_code

config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CITY_NAME = "Boston"
2+
CITY_STATE = "MA"
3+
CITY_HASHTAGS = ["Boston"]
4+
POSTAL_CODE = "02108"

social_posters/bluesky.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import requests
55

66
from abstractions import Post, PostResult, SocialPoster
7+
from config import CITY_HASHTAGS, CITY_NAME, CITY_STATE
78

89

910
class PosterBluesky(SocialPoster):
@@ -120,7 +121,7 @@ def format_post(self, pet):
120121
text += "."
121122

122123
city = ""
123-
if pet.location != "Boston, MA":
124+
if pet.location != f"{CITY_NAME}, {CITY_STATE}":
124125
city = pet.location.split(",")[0].capitalize()
125126

126127
detail_parts = []
@@ -141,7 +142,7 @@ def format_post(self, pet):
141142
text += f"\n\nLearn more and adopt me: {pet.adoption_url}"
142143

143144
species_tag = "DogsOfBluesky" if pet.species == "dog" else "CatsOfBluesky"
144-
tags = ["AdoptDontShop", "Boston", city, species_tag]
145+
tags = ["AdoptDontShop", *CITY_HASHTAGS, city, species_tag]
145146

146147
return Post(
147148
text=text,

0 commit comments

Comments
 (0)