Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mailchimp opt-in uploader #1850

Merged
merged 7 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"TWFY_VOTES_URL": {
"description": "URL to the TWFY Votes page"
},
"MAILCHIMP_API_KEY": {
"description": "Mailchimp API key"
},
"MAPIT_URL": {
"description": "URL to the MapIt API - defaults to mapit.mysociety.org"
},
Expand Down
1 change: 1 addition & 0 deletions bin/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ sed -r \
-e 's!^(.*"OPTION_TWFY_DB_NAME", *)"[^"]*"!'"\\1'twfy'!" \
-e 's!^(.*"OPTION_TWFY_MEMCACHED_HOST", *)"[^"]*"!'"\\1'memcache'!" \
-e 's!^(.*"TWFY_VOTES_URL", *)"[^"]*"!'"\\1'$TWFY_VOTES_URL'!" \
-e 's!^(.*"MAILCHIMP_API_KEY", *)"[^"]*"!'"\\1'$MAILCHIMP_API_KEY'!" \
-e 's!^(.*"OPTION_MAPIT_URL", *)"[^"]*"!'"\\1'$MAPIT_URL'!" \
-e 's!^(.*"OPTION_MAPIT_API_KEY", *)"[^"]*"!'"\\1'$MAPIT_API_KEY'!" \
-e 's!^(.*"OPTION_DEMOCRACYCLUB_TOKEN", *)"[^"]*"!'"\\1'$DEMOCRACYCLUB_TOKEN'!" \
Expand Down
2 changes: 2 additions & 0 deletions conf/general-example
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ define ("RECESSFILE","https://www.theyworkforyou.com/pwdata/parl-recesses.txt");

define("TWFY_VOTES_URL", "");

define("MAILCHIMP_API_KEY", "");

define('ENTRIES_AFTER_LEFT', '{
"10170,2014-09-08": "2014-09-07",
"11068,2008-09": "2008-08-13",
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ services:
TWFY_TEST_DB_USER: twfy
TWFY_TEST_DB_PASS: password
TWFY_VOTES_URL: ${TWFY_VOTES_URL}
MAILCHIMP_API_KEY: ${MAILCHIMP_API_KEY:-}
MAPIT_URL: ${MAPIT_URL:-https://mapit.mysociety.org/}
MAPIT_API_KEY: ${MAPIT_API_KEY:-}
DEMOCRACYCLUB_TOKEN: ${DEMOCRACYCLUB_TOKEN:-}
Expand Down
283 changes: 281 additions & 2 deletions poetry.lock

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@ pyyaml = "6.0.1"
commonlib = {path = "commonlib"}
pydantic = "^2.8.2"
sqlalchemy = "^2.0.32"
django = ">=4.2,<5.0"
mailchimp-marketing = {git = "https://github.com/mailchimp/mailchimp-marketing-python.git"}
typer = "^0.15.1"


[tool.poetry.group.dev.dependencies]
ruff = "^0.6.1"

[tool.poetry.scripts]
contact-io = "twfy_tools.utils.contact_io:app"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"


[tool.ruff]
extend-exclude = ["migrations", "commonlib", "scripts/historic"]

Expand Down
3 changes: 3 additions & 0 deletions scripts/dailyupdate
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ system './mpinfoin.pl';

# update individual division votes
system "./json2db.pl >> $cron_log";

# Add yesterdays optins to mailchimp
system "poetry run contact-io upload-yesterday >> $cron_log";
2 changes: 2 additions & 0 deletions src/twfy_tools/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ class ConfigModel(BaseModel):
TWFY_DB_NAME: str
TWFY_DB_USER: str
TWFY_DB_PASS: str
TWFY_DB_PORT: int
RAWDATA: Path
PWMEMBERS: Path
MAILCHIMP_API_KEY: str

@classmethod
def from_php_config(cls, php_config_get: BaseConfigGet):
Expand Down
42 changes: 42 additions & 0 deletions src/twfy_tools/common/enum_backport.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from enum import Enum
from typing import List, Type, TypeVar

_S = TypeVar("_S", bound="StrEnum")


class StrEnum(str, Enum):
"""
Enum where members are also (and must be) strings
"""

def __new__(cls: Type[_S], *values: str) -> _S:
if len(values) > 3:
raise TypeError("too many arguments for str(): %r" % (values,))
if len(values) == 1:
# it must be a string
if not isinstance(values[0], str):
raise TypeError("%r is not a string" % (values[0],))
if len(values) >= 2:
# check that encoding argument is a string
if not isinstance(values[1], str):
raise TypeError("encoding must be a string, not %r" % (values[1],))
if len(values) == 3:
# check that errors argument is a string
if not isinstance(values[2], str):
raise TypeError("errors must be a string, not %r" % (values[2]))
value = str(*values)
member = str.__new__(cls, value)
member._value_ = value
return member

def __str__(self):
return self.value

@staticmethod
def _generate_next_value_(
name: str, start: int, count: int, last_values: List[str]
) -> str:
"""
Return the lower-cased version of the member name.
"""
return name.lower()
Loading
Loading