Created
October 11, 2017 16:37
-
-
Save Aluriak/bd16bc9bfaff3bcc9f4d9dade0de0ca0 to your computer and use it in GitHub Desktop.
Automatically build text with each printable letter as a unique link.
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
| """ | |
| usage: <text> <file containing one link per line> | |
| """ | |
| import sys | |
| def produce(text:str, links:iter) -> str: | |
| links = iter(links) | |
| for char in text: | |
| if char not in ' \n': | |
| try: | |
| yield '[{}]({})'.format(char, next(links)) | |
| except StopIteration: | |
| print("Not enough links.") | |
| else: | |
| yield char | |
| links = sum(1 for link in links) | |
| if links: | |
| print(links, ' unused links') | |
| if __name__ == "__main__": | |
| if len(sys.argv) != 3: | |
| print(__doc__) | |
| exit(1) | |
| links_file = sys.argv[2] | |
| with open(links_file) as fd: | |
| links = (l.strip() for l in fd) | |
| print(''.join(produce(sys.argv[1], links))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment