75 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
			
		
		
	
	
			75 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
| #!/bin/bash
 | |
| 
 | |
| output=""
 | |
| 
 | |
| get_zradylko() {
 | |
|     local url="$1"
 | |
|     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')
 | |
|             main_course=$(echo "$html_snippet" | grep -oP '(?<=<h2 class="table">Hlavní jídlo<\/h2>).*?(?=<\/table>)' | sed 's/<[^>]*>//g' | awk 'NR==1')
 | |
|             weekly_course=$(echo "$html_snippet" | grep -oP '(?<=<h3>Celý týden nabízíme</h3>).*?(?=<\/table>)' | sed 's/<[^>]*>//g')
 | |
|             ;;
 | |
|         2)
 | |
|             soup=$(echo "$html_snippet" | grep -oP '(?<=<h2 class="table">Polévka<\/h2>).*?(?=<\/table>)' | sed 's/<[^>]*>//g' | awk 'NR==2')
 | |
|             main_course=$(echo "$html_snippet" | grep -oP '(?<=<h2 class="table">Hlavní jídlo<\/h2>).*?(?=<\/table>)' | sed 's/<[^>]*>//g' | awk 'NR==2')
 | |
|             weekly_course=$(echo "$html_snippet" | grep -oP '(?<=<h3>Celý týden nabízíme</h3>).*?(?=<\/table>)' | sed 's/<[^>]*>//g')
 | |
|             ;;
 | |
|         3)
 | |
|             soup=$(echo "$html_snippet" | grep -oP '(?<=<h2 class="table">Polévka<\/h2>).*?(?=<\/table>)' | sed 's/<[^>]*>//g' | awk 'NR==3')
 | |
|             main_course=$(echo "$html_snippet" | grep -oP '(?<=<h2 class="table">Hlavní jídlo<\/h2>).*?(?=<\/table>)' | sed 's/<[^>]*>//g' | awk 'NR==3')
 | |
|             weekly_course=$(echo "$html_snippet" | grep -oP '(?<=<h3>Celý týden nabízíme</h3>).*?(?=<\/table>)' | sed 's/<[^>]*>//g')
 | |
|             ;;
 | |
|         4)
 | |
|             soup=$(echo "$html_snippet" | grep -oP '(?<=<h2 class="table">Polévka<\/h2>).*?(?=<\/table>)' | sed 's/<[^>]*>//g' | awk 'NR==4')
 | |
|             main_course=$(echo "$html_snippet" | grep -oP '(?<=<h2 class="table">Hlavní jídlo<\/h2>).*?(?=<\/table>)' | sed 's/<[^>]*>//g' | awk 'NR==4')
 | |
|             weekly_course=$(echo "$html_snippet" | grep -oP '(?<=<h3>Celý týden nabízíme</h3>).*?(?=<\/table>)' | sed 's/<[^>]*>//g')
 | |
|             ;;
 | |
|         5)
 | |
|             soup=$(echo "$html_snippet" | grep -oP '(?<=<h2 class="table">Polévka<\/h2>).*?(?=<\/table>)' | sed 's/<[^>]*>//g' | awk 'NR==5')
 | |
|             main_course=$(echo "$html_snippet" | grep -oP '(?<=<h2 class="table">Hlavní jídlo<\/h2>).*?(?=<\/table>)' | sed 's/<[^>]*>//g' | awk 'NR==5')
 | |
|             weekly_course=$(echo "$html_snippet" | grep -oP '(?<=<h3>Celý týden nabízíme</h3>).*?(?=<\/table>)' | sed 's/<[^>]*>//g')
 | |
|             ;;
 | |
|         *)
 | |
|             echo "Spatnej den v tydnu brasko"
 | |
|             exit 1
 | |
|             ;;
 | |
|     esac
 | |
| 
 | |
|     # Create a JSON object with the desired fields
 | |
|     output+="{
 | |
|         \"title\": \"**$restaurant_name**\",
 | |
|         \"fields\": [
 | |
|             {
 | |
|                 \"name\": \"Polevka\",
 | |
|                 \"value\": \"$soup\"
 | |
|             },
 | |
|             {
 | |
|                 \"name\": \"Hlavni chod\",
 | |
|                 \"value\": \"$main_course\"
 | |
|             },
 | |
|             {
 | |
|                 \"name\": \"Tydenni nabidka\",
 | |
|                 \"value\": \"$weekly_course\"
 | |
|             }
 | |
|         ]
 | |
|     },"
 | |
| }
 | |
| 
 | |
| # Example usage:
 | |
| urlGarage="https://www.unasplzenchutna.cz/garage/cz/denni-nabidka/"
 | |
| get_zradylko "$urlGarage"
 | |
| 
 | |
| urlSladovnicka="https://sladovnicka.unasplzenchutna.cz/cz/denni-nabidka/"
 | |
| get_zradylko "$urlSladovnicka"
 | |
| 
 | |
| # Remove the trailing comma from the menu_data
 | |
| output="${output%,}"
 | |
| 
 | |
| # Print the complete menu data
 | |
| echo "[$output]" | jq . |