Skip to content

Instantly share code, notes, and snippets.

@qvipin
Created December 8, 2024 06:32
Show Gist options
  • Save qvipin/b2dd4244eb7a9d986c9d41dc0190ba07 to your computer and use it in GitHub Desktop.
Save qvipin/b2dd4244eb7a9d986c9d41dc0190ba07 to your computer and use it in GitHub Desktop.
Another stupid program I made, very niche problem but I wanted a solution :).
#!/usr/bin/python3
"""
Part of my stupid program's series ; Created to learn argparse and save time picking tag colors for my website. Made with ❤️.
"""
import argparse
import hashlib
def nameToColor(lexeme):
md5Hash = hashlib.md5(lexeme.encode("utf-8")).hexdigest()
numbers = (''.join([num for num in [str(ord(char)) for char in md5Hash]])).encode('utf-8').hex()
inHex = bytes.fromhex(numbers)
Sha256ed = hashlib.sha256(inHex).hexdigest()
return Sha256ed[:6]
about = "Assigns a color to any lexeme. Struggling to pick a color for a word? Simply input the lexeme with `-l <lexeme>` and get a Hex code instantly. Say goodbye to overthinking this simple task!"
parser = argparse.ArgumentParser(description = about)
parser.add_argument("lexeme", metavar='<lexeme>', action='store', help='Specify the lexeme you want a color for')
args = parser.parse_args()
print(f'Here is the color for your lexeme: #{nameToColor(args.lexeme)}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment