summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2022-07-05 10:33:21 -0400
committerBen Sima <ben@bsima.me>2022-07-05 10:33:21 -0400
commitc5f9267c04b65beb3169180c74b7ddba56172833 (patch)
treebefd2a0f845b6316998cf634015cd0f23c4b28ea
parent161dbd8e5371fdc21054657cc08a1896187c27ef (diff)
Add --dry-run
-rwxr-xr-xtwitter-bot18
1 files changed, 11 insertions, 7 deletions
diff --git a/twitter-bot b/twitter-bot
index d3ac28b..6e98576 100755
--- a/twitter-bot
+++ b/twitter-bot
@@ -101,6 +101,7 @@ parser.add_argument(
)
parser.add_argument("--excluded-terms", dest="excluded_terms", help="Terms to exclude tweets on")
parser.add_argument("--excluded-users", dest="excluded_users", help="Users to exclude tweets on")
+parser.add_argument("--dry-run", action="store_true", help="Print output to terminal instead of sending to zulip")
opts = parser.parse_args()
@@ -241,14 +242,17 @@ for status in statuses[::-1][: opts.limit_tweets]:
message = {"type": "stream", "to": [opts.stream], "subject": subject, "content": url}
- ret = client.send_message(message)
-
- if ret["result"] == "error":
- # If sending failed (e.g. no such stream), abort and retry next time
- print("Error sending message to zulip: %s" % ret["msg"])
- break
+ if opts.dry_run:
+ print(message)
else:
- since_id = status.id
+ ret = client.send_message(message)
+
+ if ret["result"] == "error":
+ # If sending failed (e.g. no such stream), abort and retry next time
+ print("Error sending message to zulip: %s" % ret["msg"])
+ break
+ else:
+ since_id = status.id
if "twitter" not in config_internal.sections():
config_internal.add_section("twitter")