summaryrefslogtreecommitdiff
path: root/color-converter.py
diff options
context:
space:
mode:
authorSimon <vesspa0330@gmail.com>2025-01-20 18:34:52 -0500
committerSimon <vesspa0330@gmail.com>2025-01-20 18:34:52 -0500
commitda81ef7e15ac5229f14e1cf45470061941afc8ac (patch)
treee512b93e2a2f417960014c23f8c3733d686a92d5 /color-converter.py
parent0d0f27b944d701553ec0e6fdc7885bb4a3297b82 (diff)
fixed hexcode validation edge-case, README update
Diffstat (limited to 'color-converter.py')
-rw-r--r--color-converter.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/color-converter.py b/color-converter.py
index a0123e0..6ed4194 100644
--- a/color-converter.py
+++ b/color-converter.py
@@ -6,7 +6,7 @@ TYPES = ['hex', 'rgb', 'cmy', 'cmyk', 'hsl', 'hsv']
HEX_LETTERS = ['a', 'b', 'c', 'd', 'e', 'f']
-OUTPUT = 'stdout'
+OUTPUT_DESTINATION = 'stdout'
VERBOSE = False
@@ -54,10 +54,10 @@ def main():
# determine if output should be (over?)written to file
if args.output :
- global OUTPUT
- OUTPUT = args.output
+ global OUTPUT_DESTINATION
+ OUTPUT_DESTINATION = args.output
if not args.append :
- output_file = open(OUTPUT, 'w')
+ output_file = open(OUTPUT_DESTINATION, 'w')
output_file.write('')
output_file.close()
@@ -446,13 +446,13 @@ def HSLorHSVToRGB(values, convertFrom) :
# If string contains a valid Hex color code, it gets returned as a string.
def validateHex(value) :
# attempt to extract hex code
- hexcode = extractValues(value, 1, True)[0]
+ hexcode = extractValues(value, 1, True)
if not hexcode :
print('ERROR: Improper format for hex code (see --help)')
return
- return hexcode
+ return hexcode[0]
# Takes in a string. Returns same list as integers if valid RGB values.
def validateRGB(color) :
@@ -460,6 +460,7 @@ def validateRGB(color) :
rgbValues = extractValues(color, 3)
if not rgbValues :
+ print('bo')
return
intValues = []
@@ -633,7 +634,7 @@ def printConversions(convertedValues) :
output.append(colorCode)
# deliver formatted output
- if OUTPUT != 'stdout' :
+ if OUTPUT_DESTINATION != 'stdout' :
'''
TODO FOR EFFICIENCY:
@@ -644,7 +645,7 @@ def printConversions(convertedValues) :
to actually open the file back in main() at the point when we evaluate args, and then close
it after everything in main() has ran... food for thought.
'''
- with open(OUTPUT, 'a', encoding='utf-8') as file :
+ with open(OUTPUT_DESTINATION, 'a', encoding='utf-8') as file :
for color in output :
file.write(color + '\n')
file.write('\n')