hi there I being trying to get nice number to work for me but no luck with suggestion from gez-mycroft processing a file that looks like this with a code that looks like that …
`
Ingredients
10 hard-cooked eggs, chopped
6 slices crispy cooked bacon, chopped
1/3 cup creamy salad dressing such as Miracle Whip®, or more
to taste
1/4 cup chopped red onion
2 tablespoons Dijon mustard
1 tablespoon honey mustard
1 tablespoon chopped fresh chives
1 teaspoon lemon juice
1 1/2 teaspoon dill
1/2 teaspoon seasoned salt
6 Kaiser rolls, split
for cnt, line in enumerate(fp):
regex = '({\d}* {\d}+\/{\d}+)'
fraction = re.search(regex, line)
if not fraction:
self.speak("{}".format(line))
continue
formatted_line = re.sub(regex, nice_number(fraction.group(1)), line)
self.speak("{}".format(formatted_line))
it output this error when it reaches a interger ie: 10 in this case
File "/home/stephen/mycroft-core/mycroft/skills/core.py", line 1075, in wrapper handler(message) File "/opt/mycroft/skills/recipe-library-skill/__init__.py", line 334, in handle_pick_snrecipe formatted_line = re.sub(regex, nice_number(fraction.group(1)), line) File "/home/stephen/mycroft-core/mycroft/util/format.py", line 262, in nice_number return nice_number_en(number, speech, denominators) File "/home/stephen/mycroft-core/mycroft/util/lang/format_en.py", line 38, in nice_number_en result = convert_to_mixed_fraction(number, denominators) File "/home/stephen/mycroft-core/mycroft/util/lang/format_common.py", line 37, in convert_to_mixed_fraction frac_number = abs(number - int_number) TypeError: unsupported operand type(s) for -: 'str' and 'int'
if I change the integer 10 to a fraction 1/4
then it crash with this error
File "/home/stephen/mycroft-core/mycroft/skills/core.py", line 1075, in wrapper handler(message) File "/opt/mycroft/skills/recipe-library-skill/__init__.py", line 334, in handle_pick_snrecipe formatted_line = re.sub(regex, nice_number(fraction.group(1)), line) File "/home/stephen/mycroft-core/mycroft/util/format.py", line 262, in nice_number return nice_number_en(number, speech, denominators) File "/home/stephen/mycroft-core/mycroft/util/lang/format_en.py", line 38, in nice_number_en result = convert_to_mixed_fraction(number, denominators) File "/home/stephen/mycroft-core/mycroft/util/lang/format_common.py", line 33, in convert_to_mixed_fraction int_number = int(number) ValueError: invalid literal for int() with base 10: '1/4 '
if I try decimal based it gives the same error as the the first example
TypeError: unsupported operand type(s) for -: 'str' and 'int'
thank you for your help