diff --git a/arxiv_post/apps/slack.py b/arxiv_post/apps/slack.py index 32a79f9..feb2bf3 100644 --- a/arxiv_post/apps/slack.py +++ b/arxiv_post/apps/slack.py @@ -16,36 +16,36 @@ # constants -PAYLOAD_TOML = """ -text = "{header}" +PAYLOAD_TOML = ''' +text = """{header}""" [[blocks]] type = "header" [blocks.text] type = "plain_text" -text = "{header}" +text = """{header}""" [[blocks]] type = "section" [blocks.text] type = "mrkdwn" -text = "*Titie:* {title}" +text = """*Titie:* {title}""" [[blocks]] type = "section" [blocks.text] type = "mrkdwn" -text = "*Authors:* {authors}" +text = """*Authors:* {authors}""" [[blocks]] type = "section" [blocks.text] type = "mrkdwn" -text = "*Summary:* {summary}" +text = """*Summary:* {summary}""" [[blocks]] type = "actions" @@ -53,7 +53,7 @@ [[blocks.elements]] type = "button" action_id = "view_arxiv" -url = "{arxiv_url}" +url = """{arxiv_url}""" [blocks.elements.text] type = "plain_text" @@ -62,12 +62,12 @@ [[blocks.elements]] type = "button" action_id = "view_pdf" -url = "{arxiv_pdf_url}" +url = """{arxiv_pdf_url}""" [blocks.elements.text] type = "plain_text" text = "View PDF" -""" +''' # logger @@ -75,14 +75,18 @@ # runtime functions -def post(articles: Sequence[Article], webhook_url: str) -> None: +def post(articles: Sequence[Article], webhook_url: str, dry_run: bool) -> None: """Post articles to Slack.""" for article in articles: try: - _post(webhook_url, json=to_payload(article)) - logger.debug(f"Posted {article.arxiv_url}") + payload = to_payload(article) + + if not dry_run: + _post(webhook_url, json=payload) + + logger.debug(f"Posted an article ({article.arxiv_url})") except TOMLDecodeError: - logger.warn(f"Failed to post {article.arxiv_url}") + logger.warn(f"Failed to post an article ({article.arxiv_url})") def to_payload(article: Article) -> Dict[str, Any]: diff --git a/arxiv_post/cli.py b/arxiv_post/cli.py index 15a4e04..e091bdd 100644 --- a/arxiv_post/cli.py +++ b/arxiv_post/cli.py @@ -49,6 +49,7 @@ def cmd_slack( n_concurrent: int = N_CONCURRENT, timeout: float = TIMEOUT, webhook_url: str = "", + dry_run: bool = False, debug: bool = False, ) -> None: """Translate and post articles to Slack. @@ -63,6 +64,7 @@ def cmd_slack( n_concurrent: Number of simultaneous execution. timeout: Timeout for each post execution (in seconds). webhook_url: URL of Slack incoming webhook. + dry_run: If True, articles are not posted to Slack. debug: If True, debug-level log messages are shown. Returns: @@ -94,7 +96,7 @@ def cmd_slack( timeout=timeout, ) - return slack.post(translated, webhook_url) + return slack.post(translated, webhook_url, dry_run) def cli() -> None: