Last active
November 8, 2024 04:38
-
-
Save jsundram/bfc4a66b15d3d5b0aa355b9bf3840a1d to your computer and use it in GitHub Desktop.
Given a cantata number, spit out some useful links, and copy them to a paste-able format suitable for, e.g. quip or a markdown document
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import sys | |
| def main(raw_input): | |
| try: | |
| # Assume BWV input isn't 0-padded, i.e. is "60" and not "060". | |
| bwv = int(raw_input) | |
| padded = '%03d' % int(bwv) | |
| bwv = str(bwv) | |
| except ValueError as e: | |
| raise Exception("Couldn't parse input as an integer: %s" % e) | |
| links = { | |
| # label: (url template, needs_0_padded_bwv?) | |
| 'Bach Cantatas Website': ('http://www.bach-cantatas.com/BWV{slug}.htm', False), | |
| 'All of Bach permalink': ('https://www.bachvereniging.nl/en/bwv/bwv-{slug}', False), | |
| 'Emmanuel Music translation': ('https://www.emmanuelmusic.org/bach-translations/bwv-{slug}', False), | |
| 'Emmanuel Music notes': ('https://www.emmanuelmusic.org/bach-notes/bwv-{slug}', False), | |
| 'Wikipedia': ('https://en.wikipedia.org/w/index.php?title=BWV_{slug}', False), | |
| } | |
| for (label, (link, pad)) in links.items(): | |
| slug = padded if pad else bwv | |
| url = link.format(slug=slug) | |
| print(f" * [{label}]({url})") | |
| if __name__ == '__main__': | |
| try: | |
| main(sys.argv[1]) | |
| except IndexError: | |
| print("Please provide a cantata BWV number") | |
| print("suggested usage: ") | |
| print("./linker.py 31 | pbcopy") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment