-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f6913bb
commit 564ab1e
Showing
10 changed files
with
90 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
[[tool.mypy.overrides]] | ||
module = [ | ||
"geopy", | ||
"mailchimp3", | ||
"uszipcode" | ||
] | ||
ignore_missing_imports = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
cryptography | ||
geopy | ||
uszipcode | ||
mailchimp3 | ||
python-Levenshtein | ||
pydantic | ||
pytest | ||
simple-salesforce | ||
uszipcode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import logging | ||
import os | ||
from typing import Any, NamedTuple | ||
|
||
from mailchimp3 import MailChimp | ||
|
||
logging.getLogger("mailchimp3.client").setLevel(logging.CRITICAL) | ||
|
||
|
||
class Coordinates(NamedTuple): | ||
latitude: float | ||
longitude: float | ||
|
||
@classmethod | ||
def from_mailchimp(cls, entry: dict[str, Any]) -> "Coordinates | None": | ||
lat: float = entry["location"]["latitude"] | ||
long: float = entry["location"]["longitude"] | ||
return cls(lat, long) if lat and long else None | ||
|
||
|
||
def get_coordinates_by_email() -> dict[str, Coordinates | None]: | ||
key = os.environ.pop("MAILCHIMP_KEY") | ||
list_id = os.environ.pop("MAILCHIMP_LIST_ID") | ||
client = MailChimp(mc_api=key) | ||
result = client.lists.members.all( | ||
list_id=list_id, | ||
fields="members.email_address,members.location.latitude,members.location.longitude", | ||
get_all=True, | ||
)["members"] | ||
return { | ||
entry["email_address"]: coords | ||
for entry in result | ||
if (coords := Coordinates.from_mailchimp(entry)) is not None | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters