Skip to content

Instantly share code, notes, and snippets.

@Aluriak
Created October 11, 2017 16:37
Show Gist options
  • Select an option

  • Save Aluriak/bd16bc9bfaff3bcc9f4d9dade0de0ca0 to your computer and use it in GitHub Desktop.

Select an option

Save Aluriak/bd16bc9bfaff3bcc9f4d9dade0de0ca0 to your computer and use it in GitHub Desktop.
Automatically build text with each printable letter as a unique link.
"""
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