Recipe skill for Mycroft_gui

sed -i "/^ self.play_list = {/a\ $LINE" $HOME/mycroft-core/skills/all-recipes-skill/__init__.py

The “Play_list” shouldn’t be hardcoded into init. Better to use the forementioned Filesystem (as it is intended)

Put it in a json. jq (a baseline package in the mycroft-core setup) is pretty good at streaming json.

or even simpler self.settings[“recipes”]=[]
self.settings[‘recipes’].append((name, place_in_.mycroft))
(ie /.config/mycroft/skills/all…/settings.json)
within python

I am sorry – all I did is follow other skills and how they were built at the time . if you like you are more then welcome to edit, modify and redistribute the above recipe skill how ever you like under whatever name you like… . I am sure you could fix it up to your liking instead of my haphazard mixtures of languages and scripting as my programing skills with python are quite lacking

but I currently like my skill. as it is as it simple easy to modify and does not rely on third party signup for it to work. and any and all tracking cookies are basically removed

and if you do modify feel free to post your edits I as I would be interested in what or how your modified it…

I blame mostly myself for the underdocumentation of parsers and formatters, as I’m the volunteer who most recently neglected to write more docs.

The number extractors in question are indeed designed to produce integers and floats. This is because most use cases expect to do math on the result, or use it as an index.

However, @JarbasAl got us around this problem a year or so back, with:
MycroftSkill.ask_selection(<iterable>)
which should account for both ordinals and ‘regular’ numbers.

edit: If you know your user will provide either an ordinal number or a ‘regular’ number, you can do extract_number(n, ordinals=True). The problem is,

>>> extract_number("Three", lang='en')
3
>>> extract_number("The third one", lang='en')
1
>>> extract_number("The third one", lang='en', ordinals=True)                                       │
3
1 Like

It’s totally doable to write this within the dev skill framework, yet i basically have to reverse engineer the bash scripts because there is no documentation. (would be nice to add a few sentences to explain what should be accomplished)

What i will do:
set up metasettings to choose the service via selene ui backend (home.my…)
set up recipe_services.py that will hold essential constants to be able to scrape that service
ressources that wont change -> /skill-path/res/
regex patterns -> /skill-path/regex/lang/[service]_*.rx
(temp) files that will change (3rd party handling,…) -> Filesystem (.mycroft/skills/skill)

online — bash basically pass your search item to the websites search url and extracts the recipe url and writes them to tmp_url file. and the last line extractor reads that temp_url and strips and numbers the recipe list for mycroft to read

process_recipe3— takes the selected number then reads the tmp_url to get the recipe url . the first extraction bit pulls the the recipe picture and saves it to a pic_url file… the next batch just processes the webpage into a readable mycroft format removing unnecessary bits

title —strips the title out for mycroft gui display

frac is is stream editing for mycroft to read fractions better as truthfully it sucks at reading fractions

the last ones are related to saving the recipe

process_recipe – has two function one to test the stripping and formatting . if you if you run it ie:

   ./process_recipe https://www.allrecipes.com/recipe/280834/turkey-beef-meatloaf/

you can test to see if the formatting is correct and if you run across a recipe that does not process correctly you can tweak it until it does… then just up date both recipe_process and recipe_process3
it also serves in the process to save the recipe

recipe just modifies and creates the play list and saves the recipe and picture to their designated folders

FAV and FILE are unused they were just testing files

email is for sending emails
GUI.sh if mycroft_gui is not running it starts it for you. it sort of a companion skill to other skill that allows me to maximize , minimize and turnoff mycroft_gui via voice commands

thanks for the write up. I think i wasn’t specific enough, sorry for that. But nevermind, i sift through it. Kinda instructional.

i meant specific sed, tr, … parts. Like
sed '/^$/d' in online
you want to delete something, but what? You define begin and end, but with no pattern. (empty lines? shouldn’t exist bc grep) In case i miss something a few specifics would be interesting
To know if i have to use python builtins (or else) or re(gex) it.

Some are readily apparent, some like the expression above aren’t

deleting empty lines that show up now and then. the next sed after that deletes duplicates lines

if you are not certain what they do . I would just comment out all the lines and run it before and after to see what it does . as some will not show up with all searches as some are specific to certain conditions . the same for process recipes not all happen with each scrape

tr stands for transform so basically '-" to " "

Having taken a look at FRAC, a suggestion for extensibility (especially given that the number extractors will be fixed sooner or later.)

The number pronouncers work fine. If, instead of sanitizing “1/3” to “one third,” you sanitize it to 0.333 or etc., then you’ll be able to do math on it for conversions and portion sizes, and still get a Mycroft-pronounceable result:

>>> x = 0.333
>>> format.nice_number(x)
'a third'
>>> format.nice_number(x / 2)
'a sixth'
>>> format.nice_number(x / 3)
'a ninth'
>>> format.nice_number(x / 5)
'a fifteenth'
>>> format.nice_number((x / 5) * 2)
'2 fifteenths'

which is fine but mycroft has no clue what this is ½ so you still need to translate for those because when it comes across them it simply skips it …

but it is your rewrite you are free to do what wish… modify how ever you like :slight_smile:

I’ll file that one over at LF. Just more characters to normalize away.

hi SGee just wondering if you made any head way and if you are stuck onany other sed commands – if so just let me know

if you want here an updated script for recipe extraction, works on allrecipe.com, foodnetwork.com, myrecipes.com and simplyrecipes.com and probably others -

edit — it also works on eatingwell.com from the looks some of these other food websites are off shoots of allrecipe – okay and also bettycrocker.com and epicurious.com

#!/bin/bash
lynx -dump $1  | 
sed -n '/^Ingredients/,/^Nutrition Facts/p;/^Nutrition Facts/q' |     ###### start and end point where recipe is 
sed -n '/^Ingredients/,/^   Allrecipes/p;/^   Allrecipes/q' | 
sed -n '/^Ingredients/,/^   Courtesy of Food Network Magazine/p;/^   Courtesy of Food Network Magazine/q' | 
sed -n '/^Ingredients/,/^   Rate This Recipe/p;/^   Rate This Recipe/q' | 
#sed '/^Ingredients/,/^   Ingredient Checklist/{//!d;};' |             ###### data between  two delimiters
sed -n '/^Ingredients/,/^Related Video/p;/^Related Video/q' | 
######## clean up of recipe ##########
sed '/^   (BUTTON) Add all ingredients to shopping list /,/^Directions/{//!d;};' |  ##### delete between the two
sed '/(BUTTON)/d' |                                                             ##### delete lines  starting with (BUTTON) 
sed '/^   Ingredient Checklist/d' |
sed '/^   Instructions Checklist/d' |
sed '/^Nutrition Facts/d' |
sed '/^       Advertisement/d' |
sed '/^   ALL RIGHTS RESERVED/d' |
sed '/^   Printed From Allrecipes.com/d' |
sed '/^   Allrecipes/d' |
sed '/^   The ingredient list now/d' |
sed '/^   Original recipe yields/d' |
sed '/^    1./d' |
sed '/^    2./d' |
sed '/^    3./d' |
sed '/^   Rate This Recipe/d' |
sed '/.jpeg/d'|
sed '/.jpg/d'|
sed '/^   Hide Images/d'|
sed '/Courtesy of Food Network Magazine/d'|
sed '/Related Video/d'|
########## Converting to AI friends words ################
sed  's/\]//g' | 
sed  's/*//g' |  
sed  's/\[//g' |  
sed  's/\   X/  /g' |  
sed  's/\C\>/Celsius /g' | 
sed  's/\F\>/Fahrenheit /g' | 
sed  's/\ m\>/ minutes/g'| 
sed  's/\ h\>/ hour/g' |  
#sed -e '/Directions/{n;N;d}' | 
sed -e '/Ingredients/{n;N;d}' |

sed 's/\.     /\n/g'

edited script to remove speech correction and moved it to FRAC example below

okay I removed the speech pattern correction form the above and added it to the FRAC ( fractional correction) since it was correcting the speech for fraction anyways I added in the speech correction for the sentences as well…

#!/bin/bash
cat $1 |
############ fraction correction #########
sed  's/½/ one half /g' | 
sed  's/1\/2/ one half /g' | 
sed  's/⅓/ one third /g' | 
sed  's/1\/3/ one third /g' |
sed  's/¼/ one quarter /g' |
sed  's/1\/4/ one quarter /g' |
sed  's/⅕/ one fith /g' |
sed  's/1\/5/ one fith /g' |
sed  's/⅙/ one sixth /g' |
sed  's/1\/6/ one sixth /g' |
sed  's/⅐/ one seventh /g' |
sed  's/1\/7/ one seventh /g' |
sed  's/⅛/ one eighth /g' |
sed  's/1\/8/ one eighth /g' |
sed  's/⅑/ one ninth /g' |
sed  's/1\/9/ one ninth /g' |
sed  's/⅒/ one tenth /g' |
sed  's/1\/10/ one tenth /g' |
sed  's/⅔/ two third /g' | 
sed  's/2\/3/ two third /g' |
sed  's/⅖/ two fith /g' |
sed  's/2\/5/ two fith /g' |
sed  's/¾/ three quarter /g' |
sed  's/3\/4/ three quarter /g' |
sed  's/⅗/ three fith /g' |
sed  's/3\/5/ three fith /g' |
sed  's/⅜/ three eighth /g' |
sed  's/3\/8/ three eighth /g' |
sed  's/⅘/ four fith /g' |
sed  's/4\/5/ four fith /g' |
sed  's/⅚/ five sixth /g' |
sed  's/5\/6/ five sixth /g' |
sed  's/⅞/ seven eighth /g' |
sed  's/7\/8/ seven eighth /g' |
sed  's/⅝/ five eighth /g' |
sed  's/5\/8/ five eighth /g' |
############## speech correction  -- recombines broken sentences into  strings then  breaks line at period #########
 sed 's/^/ /' |
 tr -d '\r\n' |
 sed 's/\. /\n/g' | 
 sed 's/\*\*\* /\n/g' |
 sed  's/\*//g' |
 sed 's/$/\./' | 
###### end of line break  rejoining and division  ########
####### correction of  structure after rejoining line breaks #####
 sed  's/      //g' | 
sed  's/\Step\>/######Step /g' | sed 's/######/\n/g'  |
sed  's/\*//g' |
sed 's/   /\n/g'  |
 sed 's/ Directions/\n&/'  |
sed 's/ Steps/\n&/'  |
#sed 's/[0-9]  /\n&/'  |
sed 's:\(Step  [0-9]\):\1\n:g'|
sed 's/\.     /\n/g'
######### added modifications to handle the  extra recipe sites mentioned above

I updated github repository with the newest updates to the allrecipe.skill

  1. updated the speech correction script- auto correct fraction speech and sentence structure
  2. updated to include read ingredients and read directions function
  3. update to scraping scrape for tolerance of multiple recipe websites
  4. updated for the possibility to use different language recipe sites

okay have fun

example :slight_smile: ingredients & directions function, usuful due to increased font size and if the recipe screen times out all have to do is say read ingredient or read directions and it will display the last recipe you viewed


I’m on it. Rewrote and modularized the code in 3 parts.The Call(s), data aggregation (from various sources) and data processing (gui stuff). Now i’m onto the email, proper html formating and so on with verious ideas to go forward (email distribution to contacts,…)

Everything local by now, but i will PM you the git if things get serious.

sounds nice - i was going to add multiple email contacts, and was thinking about sending email in html formatting for so i could send image … but glad my skill has inspired you to take it a step further :slight_smile:

Don’t expect it too soon, since i have to factor in category management (add, change,…), non-internet sources (eg. bring in recipes that are not yet digital) and whatever else comes to mind.

Furthermore i want to see what the soon to be implemented skill-API (essentially call methods from other skills) has in stake to progress this even more

no worries -I am sure it will be lovely when you release it -i had a script for manually inserting recipes and l did it by categories as well in my previous recipe skill that did not work with the GUI. . or maybe you noticed that. but i simplified if in this version as it more visual versus auditory

I just downloaded and tried this skill.
I am getting this error.

/bin/sh: line 1: skills/Energy-Monitor/./GUI.sh: No such file or directory
sh: line 1: skills/all-recipes-skill/bash/en-us/./online: No such file or directory
2021-02-19 10:16:04.700 | ERROR    | 3044822 | mycroft.skills.mycroft_skill.mycroft_skill:on_error:835 | An error occurred while processing a request in All Recipes
Traceback (most recent call last):
File "/home/jbrodie/Software/Mycroft/builderjer/mycroft-core/mycroft/skills/mycroft_skill/event_container.py", line 66, in wrapper
handler(message)
File "/opt/mycroft/skills/all-recipe-skill.krywenko/__init__.py", line 431, in handle_online_getrecipe
filepath = open("tmp_recipe","r")
FileNotFoundError: [Errno 2] No such file or directory: 'tmp_recipe'

I am assuming that it is a permission issue, because I have had issues wit Manjaro and mycroft. I’m just not sure what directory it is actually looking for so I can change the permissions

sorry never notice that just change lines with ( but I will fix it up at github)

skill/Energy-Monitor/./GUI.sh
to
skills/all-recipe-skill/./GUI.sh

it fixed on github sorry it was linked to another skill I never noticed the error or you can comment out the lines as well as it just open mycrofy gui if it not running