From 287b02cb05cc5a917c9f0c265022b372bf70c8f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Rod=C3=A9s-Guirao?= Date: Tue, 7 Jan 2025 02:57:43 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=89=20demo=20housekeeper=20(#3797)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🎉 demo housekeeper * reflect new names * wip --- apps/housekeeper/cli.py | 20 +++++++++++++++++--- apps/housekeeper/utils.py | 4 ++-- etl/grapher/model.py | 6 +++--- scripts/housekeeper.sh | 11 ++++++++--- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/apps/housekeeper/cli.py b/apps/housekeeper/cli.py index f7a9e0953949..1c3c78e113d7 100644 --- a/apps/housekeeper/cli.py +++ b/apps/housekeeper/cli.py @@ -1,5 +1,7 @@ """Keep things in OWID catalog clean by regularly checking and reviewing content.""" +from typing import Optional + import click from rich_click import RichCommand @@ -18,12 +20,24 @@ @click.command("housekeeper", cls=RichCommand, help=__doc__) -@click.option("--review-type", "-t", type=click.Choice(REVIEW_TYPES, case_sensitive=False)) -def main(review_type: str): +@click.option( + "--review-type", + "-t", + type=click.Choice(REVIEW_TYPES, case_sensitive=False), + help="Type of the review", +) +@click.option( + "--channel", + "-c", + type=str, + help=f"Name of the slack channel to send the message two. If None, {CHANNEL_NAME} will be used", +) +def main(review_type: str, channel: Optional[str] = None): + channel_name = CHANNEL_NAME if channel is None else channel # Review charts if review_type == "chart": send_slack_chart_review( - channel_name=CHANNEL_NAME, + channel_name=channel_name, slack_username=SLACK_USERNAME, icon_emoji=ICON_EMOJI, ) diff --git a/apps/housekeeper/utils.py b/apps/housekeeper/utils.py index 6fa23f70c580..c7ef9aefa7bf 100644 --- a/apps/housekeeper/utils.py +++ b/apps/housekeeper/utils.py @@ -6,12 +6,12 @@ def get_reviews_id(object_type: str): with Session(OWID_ENV.engine) as session: - return gm.HousekeepingSuggestedReview.load_reviews_object_id(session, object_type=object_type) + return gm.HousekeeperReview.load_reviews_object_id(session, object_type=object_type) def add_reviews(object_type: str, object_id: int): with Session(OWID_ENV.engine) as session: - gm.HousekeepingSuggestedReview.add_review( + gm.HousekeeperReview.add_review( session=session, object_type=object_type, object_id=object_id, diff --git a/etl/grapher/model.py b/etl/grapher/model.py index 9f43da1773f6..91d983da944b 100644 --- a/etl/grapher/model.py +++ b/etl/grapher/model.py @@ -128,8 +128,8 @@ def create_table(cls, engine: Engine, if_exists: Literal["fail", "replace", "ski raise ValueError(f"Unrecognized value for if_exists: {if_exists}") -class HousekeepingSuggestedReview(Base): - __tablename__ = "housekeeping_suggested_reviews" +class HousekeeperReview(Base): + __tablename__ = "housekeeper_reviews" id: Mapped[int] = mapped_column( Integer, @@ -153,7 +153,7 @@ class HousekeepingSuggestedReview(Base): objectId: Mapped[int] = mapped_column(Integer, nullable=False) @classmethod - def load_reviews(cls, session: Session, object_type: Optional[str] = None) -> list["HousekeepingSuggestedReview"]: + def load_reviews(cls, session: Session, object_type: Optional[str] = None) -> list["HousekeeperReview"]: if object_type is None: vars = session.scalars(select(cls)).all() return list(vars) diff --git a/scripts/housekeeper.sh b/scripts/housekeeper.sh index 518ca258c609..58d6fd5dcf05 100755 --- a/scripts/housekeeper.sh +++ b/scripts/housekeeper.sh @@ -11,9 +11,14 @@ start_time=$(date +%s) HOUR=$(TZ=Europe/Berlin date +%H) echo '--- Keep OWID clean' -cd /home/owid/etl -if [ "$HOUR" -eq "01" ]; then - uv run etl d housekeeper --review-type chart +# cd /home/owid/etl +if [ "$HOUR" -eq "03" ]; then + echo "--- Suggesting chart reviews..." + if [ -n "$1" ]; then + uv run etl d housekeeper --review-type chart --channel "$1" + else + uv run etl d housekeeper --review-type chart + fi fi end_time=$(date +%s)