obedy/zradylko.sh

139 lines
6.1 KiB
Bash
Executable File

#!/bin/bash
output=""
get_zradylko() {
local url="$1"
local commonName="$2"
local icon="$3"
local html_snippet=$(curl -s "$url")
local day_of_week=$(date '+%u')
restaurant_name=$(echo "$html_snippet" | grep -oP '(?<=<title>).*?(?=</title>)')
case "$day_of_week" in
1)
soup=$(echo "$html_snippet" | grep -oP '(?<=<h2 class="table">Polévka<\/h2>).*?(?=<\/table>)' | sed 's/<[^>]*>//g' | awk 'NR==1' | sed 's/&nbsp;/ /g')
main_course=$(echo "$html_snippet" | grep -oP '(?<=<h2 class="table">Hlavní jídlo<\/h2>).*?(?=<\/table>)' | sed 's/<[^>]*>//g' | awk 'NR==1' | sed 's/&nbsp;/ /g')
weekly_course=$(echo "$html_snippet" | grep -oP '(?<=<h3>Celý týden nabízíme</h3>).*?(?=<\/table>)' | sed 's/<[^>]*>//g' | sed 's/&nbsp;/ /g')
;;
2)
soup=$(echo "$html_snippet" | grep -oP '(?<=<h2 class="table">Polévka<\/h2>).*?(?=<\/table>)' | sed 's/<[^>]*>//g' | awk 'NR==1' | sed 's/&nbsp;/ /g')
main_course=$(echo "$html_snippet" | grep -oP '(?<=<h2 class="table">Hlavní jídlo<\/h2>).*?(?=<\/table>)' | sed 's/<[^>]*>//g' | awk 'NR==2' | sed 's/&nbsp;/ /g')
weekly_course=$(echo "$html_snippet" | grep -oP '(?<=<h3>Celý týden nabízíme</h3>).*?(?=<\/table>)' | sed 's/<[^>]*>//g' | sed 's/&nbsp;/ /g')
;;
3)
soup=$(echo "$html_snippet" | grep -oP '(?<=<h2 class="table">Polévka<\/h2>).*?(?=<\/table>)' | sed 's/<[^>]*>//g' | awk 'NR==1' | sed 's/&nbsp;/ /g')
main_course=$(echo "$html_snippet" | grep -oP '(?<=<h2 class="table">Hlavní jídlo<\/h2>).*?(?=<\/table>)' | sed 's/<[^>]*>//g' | awk 'NR==3' | sed 's/&nbsp;/ /g')
weekly_course=$(echo "$html_snippet" | grep -oP '(?<=<h3>Celý týden nabízíme</h3>).*?(?=<\/table>)' | sed 's/<[^>]*>//g' | sed 's/&nbsp;/ /g')
;;
4)
soup=$(echo "$html_snippet" | grep -oP '(?<=<h2 class="table">Polévka<\/h2>).*?(?=<\/table>)' | sed 's/<[^>]*>//g' | awk 'NR==1' | sed 's/&nbsp;/ /g')
main_course=$(echo "$html_snippet" | grep -oP '(?<=<h2 class="table">Hlavní jídlo<\/h2>).*?(?=<\/table>)' | sed 's/<[^>]*>//g' | awk 'NR==4' | sed 's/&nbsp;/ /g')
weekly_course=$(echo "$html_snippet" | grep -oP '(?<=<h3>Celý týden nabízíme</h3>).*?(?=<\/table>)' | sed 's/<[^>]*>//g' | sed 's/&nbsp;/ /g')
;;
5)
soup=$(echo "$html_snippet" | grep -oP '(?<=<h2 class="table">Polévka<\/h2>).*?(?=<\/table>)' | sed 's/<[^>]*>//g' | awk 'NR==1' | sed 's/&nbsp;/ /g')
main_course=$(echo "$html_snippet" | grep -oP '(?<=<h2 class="table">Hlavní jídlo<\/h2>).*?(?=<\/table>)' | sed 's/<[^>]*>//g' | awk 'NR==5' | sed 's/&nbsp;/ /g')
weekly_course=$(echo "$html_snippet" | grep -oP '(?<=<h3>Celý týden nabízíme</h3>).*?(?=<\/table>)' | sed 's/<[^>]*>//g' | sed 's/&nbsp;/ /g')
;;
*)
echo "Spatnej den v tydnu brasko"
exit 1
;;
esac
# Create a JSON object with the desired fields
# shellcheck disable=SC2016
output=''${output}'
{
"title": "**'"$commonName"'**",
"author": {
"name": "'"$restaurant_name"'",
"icon_url": "'"${icon}"'"
},
"fields": [
{
"name": "Polevka",
"value": "'"$soup"'"
},
{
"name": "Hlavni chod",
"value": "'"$main_course"'"
},
{
"name": "Tydenni nabidka",
"value": "'"$weekly_course"'"
}
]
},'
}
get_habibi() {
local url="$1"
local commonName="$2"
local icon="$3"
# Create a JSON object with the desired fields
# shellcheck disable=SC2016
output=''${output}'
{
"title": "**'"$commonName"'**",
"author": {
"name": "'"$commonName"'",
"icon_url": "'"${icon}"'"
},
"fields": [
{
"name": "Menu",
"value": "'"https://www.foodora.cz/restaurant/qus9/kebab-house-galerie-slovany?utm_source=google&utm_medium=organic&utm_campaign=google_reserve_place_order_action"'"
}
]
},'
}
get_agent_orange() {
local url="$1"
local commonName="$2"
local icon="$3"
# Create a JSON object with the desired fields
# shellcheck disable=SC2016
output=''${output}'
{
"title": "**'"$commonName"'**",
"author": {
"name": "'"$commonName"'",
"icon_url": "'"${icon}"'"
},
"fields": [
{
"name": "Menu",
"value": "'"https://www.foodora.cz/restaurant/r2xt/bistro-pho-time?utm_source=google&utm_medium=organic&utm_campaign=google_reserve_place_order_action"'"
}
]
},'
}
urlGarage="https://www.unasplzenchutna.cz/garage/cz/denni-nabidka/"
get_zradylko "$urlGarage" "Salieriho bar" "https://png.pngtree.com/png-vector/20240211/ourlarge/pngtree-italy-round-flag-peeling-sticker-transparent-background-vector-png-image_11738118.png"
urlSladovnicka="https://sladovnicka.unasplzenchutna.cz/cz/denni-nabidka/"
get_zradylko "$urlSladovnicka" "V. pavilón" "https://i0.wp.com/life4you.cz/wp-content/uploads/2022/09/Pilsner-Urquell.png?fit=480%2C480&ssl=1"
get_habibi "Habibi" "Habibi" "https://upload.wikimedia.org/wikipedia/commons/thumb/8/81/Flag_of_the_Islamic_State_of_Iraq_and_the_Levant.png/800px-Flag_of_the_Islamic_State_of_Iraq_and_the_Levant.png"
get_agent_orange "Agent Orange" "Agent Orange" "https://www.postavy.cz/foto-dila/vietcong-foto.jpg"
output=''${output}'
{
"image": {
"url": '"$(curl "https://tenor.googleapis.com/v2/search?q=jirka+babica&key=AIzaSyBslfnEs3bkLvwbqp3iUWqKAHyop5aldEo&client_key=qrreader&limit=1&random=true&country=CZ" | jq .results[0].media_formats.gif.url)"'
}
},'
# TODO
# get_microsoft_support
# Print the complete menu data
echo "$output"