Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # Dependencies:
- # sudo apt install golang whiptail
- # export GOPATH=$HOME/go
- # export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
- # go get github.com/ericchiang/pup
- install_whiptail() {
- if [ -f /etc/apt/sources.list ]; then
- sudo apt install whiptail
- fi
- }
- check_dependencies() {
- if ! dpkg-query -W --showformat='${db:Status-Status}' whiptail 2>&1 | grep -q installed; then
- whiptail --title "Dependência não instalada" --yesno "Uma dependência não está instalada.\nDeseja instalá-la?" 8 40
- if [ $? -eq 0 ]; then
- install_whiptail
- else
- exit 0
- fi
- fi
- }
- get_channel() {
- CANAL=$(whiptail --inputbox "Digite o canal com letras minúsculas:" --title "Qual o canal?" 8 40 3>&1 1>&2 2>&3)
- # Use a map to match channel names to URLs
- channel_map=(
- ["globo"]="https://meuguia.tv/programacao/canal/GRD"
- ["band"]="https://meuguia.tv/programacao/canal/BAN"
- ["mtv"]="https://meuguia.tv/programacao/canal/MTV"
- ["record"]="https://meuguia.tv/programacao/canal/REC"
- ["redetv"]="https://meuguia.tv/programacao/canal/RTV"
- # ...
- )
- # Get the corresponding URL for the provided channel name
- if [[ -z "${channel_map[$CANAL]}" ]]; then
- whiptail --title "Erro" --msgbox "Canal não cadastrado ou escrito com letras maiúsculas." 8 40
- exit 0
- fi
- CANAL="${channel_map[$CANAL]}"
- }
- set_txt() {
- # Use curl and pup to extract data from the specified URL
- curl -s "$CANAL" | pup '.lileft text{}' > horarios.txt
- curl -s "$CANAL" | pup 'h2 text{}' > filmes.txt
- paste horarios.txt filmes.txt > horarios_filmes.txt
- # Clean up temporary files
- rm -rf horarios.txt filmes.txt
- # Report success if the file was created
- if [ -f horarios_filmes.txt ]; then
- whiptail --title "Sucesso" --msgbox "Arquivo criado com sucesso." 8 40
- fi
- }
- check_dependencies
- get_channel
- set_txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement