Új hozzászólás Aktív témák

  • douggutaby

    tag

    válasz dabadab #2496 üzenetére

    Hibakezelés még kell, de kb ennyi. A sed-del lépegetést lehetett volna szebben is, de nekem jó lesz így is :)
    #!/bin/bash

    this_date=$1
    year=$(date --date="$this_date" "+%Y")
    month=$(date --date="$this_date" "+%m" | sed 's/^0*//')
    day=$(date --date="$this_date" "+%d" | sed 's/^0*//')
    result=""

    content=$(curl -s https://www.hrportal.hu/munkaido_${year}.html)
    start_num=$(echo "$content" | grep -n "<article>" | cut -d ":" -f 1)
    end_num=$(echo "$content" | grep -n "</article>" | cut -d ":" -f 1)

    content=$(echo "$content" | sed -n "$start_num,${end_num}p")
    month_num=$(echo "$content" | grep -n caltrm | grep -v munkanap | sed "${month}q;d" | cut -d ":" -f 1)
    day_type=$(echo "$content" | sed -n "${month_num},\$p" | grep "caltd.*>${day}<" | head -1 | cut -d '"' -f 2)

    case "$day_type" in
      caltdb | caltdred | caltdsarga)
        result="hetvege"
        ;;
      caltdszurke | caltd)
        result="munkanap"
        ;;
    esac

    echo $result

    [ Szerkesztve ]

Új hozzászólás Aktív témák