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 script to update picture links for tokens from Scryfall API #209

Merged
merged 1 commit into from
Feb 17, 2024

Conversation

Elarnon
Copy link
Contributor

@Elarnon Elarnon commented Mar 12, 2023

Fixes #201

This script changes the links from the old CND on c1.scryfall.com to links to the new CDN on cards.scryfall.io.

The refresh.py script can read a tokens.xml file containing CDN picURLs of either version, and makes requests to the Scryfall API to generate the most up-to-date URLs for each token.

The script can be run with:

$ python3 refresh.py -i tokens.xml
$ python3 refresh.py -i challenge_tokens.xml

This avoids using api.scryfall.com URLs for the tokens (which are rate-limited) while still being able to update the file with new URLs by running the script.

The Scryfall picURL must be in one of those forms:

- https://c1.scryfall.com/file/scryfall-cards/<version>/<face>/*/*/<uuid>.jpg
- https://cards.scryfall.io/<version>/<face>/*/*/<uuid>.jpg
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure. It looks like only cards.scryfall.io is used for cards currently.

Maybe it would make sense for the script to check that it can re-parse the resolved URL and print out an error otherwise? This would indicate a change in scryfall's URLs that needs to be reflected in the script.

@ZeldaZach
Copy link
Member

I'd be okay with something like this, but it would need to be updated to address conflicts, and potentially apart of the CLI GHA

@Elarnon
Copy link
Contributor Author

Elarnon commented Nov 1, 2023

Rebased the PR. I have also separate the commit introducing the script from the actual update to tokens.xml to make it slightly easier to work with.

apart of the CLI GHA

Can you point me to the file where this should happen?

@tooomm
Copy link
Member

tooomm commented Nov 5, 2023

Can you point me to the file where this should happen?

Not exactly sure, but I guess Zach is suggesting to have a GitHub action workflow that runs the script on a schedule to keep the links updated.
Such configuration files are placed in .github/workflows.
If you need help, let me know. I can also look into that.


but it would need to be updated to address conflicts

@Elarnon
Copy link
Contributor Author

Elarnon commented Nov 11, 2023

Can you point me to the file where this should happen?

Not exactly sure, but I guess Zach is suggesting to have a GitHub action workflow that runs the script on a schedule to keep the links updated. Such configuration files are placed in .github/workflows. If you need help, let me know. I can also look into that.

Ah, I thought from the previous message that there was a specific workflow that was meant to be added to. I can set up a workflow to run the script on a schedule, but I would need to know when and how the script must run — I don't think that this is my call to make. I also think that having the script w/o the automation is a valuable first step and that automation could happen separately (when someone has the time to do it), but that is not my call to make either.

but it would need to be updated to address conflicts

I did this last time I commented, but then the tokens.xml file on master was changed :) I have just reran the script again, but it makes little sense for me to keep doing it if the PR is not going to be merged.

@tooomm
Copy link
Member

tooomm commented Nov 12, 2023

I also think that having the script w/o the automation is a valuable first step and that automation could happen separately (when someone has the time to do it), but that is not my call to make either.

Sure! We can look into it in a second step.

@tooomm tooomm changed the title Update token links to cards.scryfall.io Add script to update picture links for tokens from Scryfall API Nov 12, 2023
@tooomm
Copy link
Member

tooomm commented Dec 17, 2023

but it would need to be updated to address conflicts

I did this last time I commented, but then the tokens.xml file on master was changed :) I have just reran the script again, but it makes little sense for me to keep doing it if the PR is not going to be merged.

Oh sorry, I misunderstood the "conflicts" part I guess.

I was referring to #209 (review):

Maybe it would make sense for the script to check that it can re-parse the resolved URL and print out an error otherwise? This would indicate a change in scryfall's URLs that needs to be reflected in the script.

Do you still want to look into that and think it's helpful?


Also, do you mind removing the changes of the scrip run from the PR to have it cleaner?
That keep this PR about the script and not the changes it'll do. That way, we also avoid conflicts in case the token file changes in between again - as you realized, code reviews take a while and people only pop in once in a while...

Fix Cockatrice#201. This changes the links from the old CND on c1.scryfall.com to
links to the new CDN on cards.scryfall.io.

The changes are automated: the refresh.py script can read a tokens.xml
file containing CDN picURLs of either version, and makes requests to the
Scryfall API to generate the most up-to-date URLs for each token.

The script can be run with:

  $ python3 refresh.py -i tokens.xml
  $ python3 refresh.py -i challenge_tokens.xml

This avoids using api.scryfall.com URLs for the tokens (which are
rate-limited) while still being able to update the file with new URLs by
running the script.
Elarnon added a commit to Elarnon/Magic-Token that referenced this pull request Dec 17, 2023
This is the result of running the script from Cockatrice#209, without the script
itself.
@Elarnon
Copy link
Contributor Author

Elarnon commented Dec 17, 2023

I was referring to #209 (review):

Maybe it would make sense for the script to check that it can re-parse the resolved URL and print out an error otherwise? This would indicate a change in scryfall's URLs that needs to be reflected in the script.

Do you still want to look into that and think it's helpful?

This is easy to do, I only did not do it because there was no acknowledgement of the suggestion. I have added it to the script (see here).

Also, do you mind removing the changes of the scrip run from the PR to have it cleaner? That keep this PR about the script and not the changes it'll do. That way, we also avoid conflicts in case the token file changes in between again - as you realized, code reviews take a while and people only pop in once in a while...

I have removed the changes to tokens.xml from the PR and opened #249 with only the tokens.xml changes (I will not keep updating that PR, but at least it can be merged separately without having to review the script if wanted; feel free to close it otherwise).

@tooomm
Copy link
Member

tooomm commented Dec 17, 2023

Thank you!
I'll leave this a few more days open for @ZeldaZach or @ebbit1q to check and comment.

This is easy to do, I only did not do it because there was no acknowledgement of the suggestion. I have added it to the script (see here).

It would be easier to spot and review this change/addition if you not force pushed and overwrote the commit history. ;)
We will squash all commits on merge anyway.

@Elarnon
Copy link
Contributor Author

Elarnon commented Dec 17, 2023

It would be easier to spot and review this change/addition if you not force pushed and overwrote the commit history. ;) We will squash all commits on merge anyway.

You can use the "Compare" button to see the changes:
image

Although you are right, it probably should have been a separate commit; I was already rebasing to remove the changes to the tokens.xml (got scared by #220) and didn't think too much about it, sorry!

@tooomm tooomm requested a review from ebbit1q February 3, 2024 15:24
@tooomm
Copy link
Member

tooomm commented Feb 3, 2024

You can use the "Compare" button to see the changes: image

I did not know and never realized this option. That helps with changes that are force pushed. 👍

@tooomm tooomm merged commit 0149a59 into Cockatrice:master Feb 17, 2024
@tooomm
Copy link
Member

tooomm commented Feb 17, 2024

I think we can move on here as there are no further comments or request.

Edit: Opened #259 for the CI automation on a reasonable schedule which takes care of creating PRs to keep the image links up to date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move to *.scryfall.io for card sources
3 participants