Skip to content
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ The following variables are available. You can also look at the [action.yml](act
| previous_filename | The previous filename (for manual tesing or running alongside update) | false | unset |
| keys | Comma separated list of keys to post (defaults to url) | false | url |
| unique | Field to use to determine uniqueness | true | url |
| hashtag | A hashtag to use (defaults to `#Rseng`) | false | #RSEng |
| hashtag | A comma separated list of hashtags to use (defaults to `#RSEng`) | false | #RSEng |
| test | Test the updater (ensure there are jobs) | true | false |
| deploy | Global deploy across any service set to true? | true | true |
| bluesky_deploy | Deploy to BlueSky? | true | false |
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ inputs:
required: true
default: url
hashtag:
description: A hashtag to use (defaults to <hashtag>Rseng)
description: A comma separated list of hashtags to use (defaults to <hashtag>RSEng)
required: false
default: "#RSEng"
test:
Expand Down
22 changes: 13 additions & 9 deletions find-updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def get_parser():
"--hashtag",
dest="hashtag",
default="#RSEng",
help="A hashtag (starting with #) to include in the post, defaults to #RSEng",
help="A comma separated list of hashtags (starting with #) to include in the post, defaults to #RSEng",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For args that are intended to become lists, you can use action="append" and then have the default be None, and do something like:

hashtags = args.hashtags or []

To ensure you get an empty list. The default can also be ["RSEng"] as a single item to reproduce what you have now. Then on the command line append works like this:

find-updates.py --hashtag first --hashtag second

So I would keep the argument dest as just hashtag to match the user interaction better, and then parse args.hashtag as a list. Nit - I would remove the # since it can be parsed as a comment. But if you quote it, probably OK too. Do what you think is best, and just document it for the developer user.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good idea. I like this method better. I'll make that change soon.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I've partially addressed this by returning the command-line argument to its original name. It can still accept a comma-separated list of hashtags though.

I considered the suggestion to supply it as a list in the first place, but there are two reasons that I'd rather not do that and just keep it as a string:

  1. the append method makes it more awkward to supply a default value because the default value would still be included in the list. So, for example, #RSEng would always be included even if what you really wanted was #one, #two, #three exclusively. The default option could be supplied later in main, but that feels weird to me when there's already a nice way to supply a default in argparse.

  2. changing it to a list would require a change to the configuration of existing workflows, and if we agree that we don't want to change the command-line argument for that reason, perhaps we shouldn't change the type of hashtag either. I'd prefer to keep it as a comma-separated string as is already done for keys. I think it's less error-prone and easier to supply in the yaml.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the default, what you'd want to do is set to None, and then:

args.hashtag = args.hashtag or ["#RSEng"]

Agree on the second point.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the default, what you'd want to do is set to None, and then:

args.hashtag = args.hashtag or ["#RSEng"]

I'm pretty sure I understand what you mean, but I'd rather not do it this way if it's OK with you. Are you still willing to merge it without this change?

If so, I'll run a few more tests and point you to the results.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no, I'm good with what you have - I'm just showing for the future how I'd handle the issue you pointed out.

)

update.add_argument(
Expand Down Expand Up @@ -282,7 +282,7 @@ def deploy_slack(webhook, message):
)


def deploy_bluesky(client, entry, keys, hashtag):
def deploy_bluesky(client, entry, keys, hashtags):
"""
Deploy to bluesky. We add the job link separately.
"""
Expand All @@ -291,11 +291,12 @@ def deploy_bluesky(client, entry, keys, hashtag):
# Prepare the post, but without the url
post = prepare_post(entry, keys, without_url=True)
choice = random.choice(icons)
message = f"New {hashtag} Job! {choice}\n"
print(message)

# Add the text to the textbuilder
tb.text(message)
# seems like a clumsy way to build such a message...
tb.text("New ")
for hashtag in hashtags:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do list comprehension instead. And I think tb.text() is going to need to be the entire message? I'm not sure you need "New" that is probably from an example. I would remove that, then do:

# Assume a mixture or erroneous
tags = ["one", "#two", "#three"]

# Clean (normalize) all tags of #
tags = [x.replace('#', "") for x in tags]

# Add back #
tags = " ".join([f"#{tag}" for tag in tags])
message = f"New {tags} Job! {choice}\n"
New #one #two #three Job! 💼

You can technically combine the two cleanup and add back into one comprehension, but I'd choose this one because it's easier to read.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I did a slightly cleaner replacement in main() where the static "dead" string of tags is supplied, and slightly improved the form in deploy_bluesky(). I'd prefer to not use a list comprehension there because I think it would be less readable.
The reason you see what looks like a bare "New" there is because it's building up the bsky post piecemeal, so "New " + linkified tags + "Job!...".

tb.tag(hashtag, hashtag.lstrip("#")).text(" ")
tb.text(f"Job! {choice}\n")
anchor=entry.get('title') or entry.get('name') or entry.get('url')
tb.link(anchor, entry.get('url'))
tb.text("\n" + post)
Expand Down Expand Up @@ -370,6 +371,9 @@ def help(return_code=0):
# Parse keys into list
keys = [x for x in args.keys.split(",") if x]

# Parse hashtags into list
hashtags = [x for x in args.hashtag.split(",") if x]

# Find new posts in updated
previous = set()
missing_count = 0
Expand Down Expand Up @@ -410,8 +414,8 @@ def help(return_code=0):
# Prepare the post
post = prepare_post(entry, keys)
choice = random.choice(icons)
message = f"New {args.hashtag} Job! {choice}: {post}"
newline_message = f"New {args.hashtag} Job! {choice}\n{post}"
message = f"New {(" ".join(hashtags))} Job! {choice}: {post}"
newline_message = f"New {(" ".join(hashtags))} Job! {choice}\n{post}"
print(message)

# Convert dates, etc. back to string
Expand All @@ -435,7 +439,7 @@ def help(return_code=0):
deploy_twitter(twitter_client, newline_message)

if args.deploy_bluesky and bluesky_client:
deploy_bluesky(bluesky_client, entry, keys, args.hashtag)
deploy_bluesky(bluesky_client, entry, keys, hashtags)

# If we are instructed to deploy to mastodon and have a client
if args.deploy_mastodon and mastodon_client:
Expand Down