Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lang="ru"
- place="Нижний Новгород"
- file=$(curl -s -o - "http://pda.rp5.ru/?lang=${lang}&q=${place}")
- links=$(echo ${file} | grep -o -e "p class=\"navy\">.*<form id=\"f\"" | grep -o -e "=[^=]*" | tail -n +2 | head -n -1)
- code=$(echo ${links} | grep -Eo -e "\"[[:digit:]]+" | grep -Eo -e "[[:digit:]]+" | head -n 1)
- name=$(echo ${links} | grep -Eo -e "${lang}\">[^<]+" | grep -Eo -e ">.+" | grep -Eo -e "[^>]+" | head -n 1)
- file=$(wget -q -O - "http://rp5.ru/${code}/${lang}")
- table6=$(echo ${file} | grep -Pzo "ftab_6_content(.|\n)*ftab_3_content")
- dates6=($(echo ${table6} | grep -o -e "monthDay[^\<]*" | grep -o -e "[^>]*$"))
- times6=($(echo ${table6} | grep -Eo -e "\"[nd][[:digit:]]? underlineRow\">[[:digit:]]+" | grep -o -e "[^>]*$"))
- temperatures6=($(echo ${table6} | grep -Eo -e "class=\"t_0\">[^/]*" | grep -Eo -e ">[-[:digit:]]+" | grep -Eo -e "[-[:digit:]]+"))
- clouds6=($(echo ${table6} | grep -Eo -e "class=\"cc_0\"[^o]*" | grep -Eo -e "c[dn][[:digit:]]" | grep -Eo -e "[[:digit:]]+"))
- conditions6=($(echo ${table6} | grep -Eo -e "class=\"pr_0\"[^/]*" | grep -Eo -e "wp_[^\"_]*"))
- pressure6=($(echo ${table6} | grep -Eo -e "class=\"p_0\">[^/]*" | grep -Eo -e ">[-[:digit:]]+" | grep -Eo -e "[-[:digit:]]+"))
- table3=$(echo ${file} | grep -Pzo "ftab_3_content(.|\n)*ftab_1_content")
- dates3=($(echo ${table3} | grep -o -e "monthDay[^\<]*" | grep -o -e "[^>]*$"))
- times3=($(echo ${table3} | grep -Eo -e "\"[nd][[:digit:]]? underlineRow\">[[:digit:]]+" | grep -o -e "[^>]*$"))
- temperatures3=($(echo ${table3} | grep -Eo -e "class=\"t_0\">[^/]*" | grep -Eo -e ">[-[:digit:]]+" | grep -Eo -e "[-[:digit:]]+"))
- clouds3=($(echo ${table3} | grep -Eo -e "class=\"cc_0\"[^o]*" | grep -Eo -e "c[dn][[:digit:]]" | grep -Eo -e "[[:digit:]]+"))
- conditions3=($(echo ${table3} | grep -Eo -e "class=\"pr_0\"[^/]*" | grep -Eo -e "wp_[^\"_]*"))
- pressure3=($(echo ${table3} | grep -Eo -e "class=\"p_0\">[^/]*" | grep -Eo -e ">[-[:digit:]]+" | grep -Eo -e "[-[:digit:]]+"))
- table1=$(echo ${file} | grep -Pzo "ftab_1_content(.|\n)*html")
- dates1=($(echo ${table1} | grep -o -e "monthDay[^\<]*" | grep -o -e "[^>]*$"))
- times1=($(echo ${table1} | grep -Eo -e "\"[nd][[:digit:]]? underlineRow\">[[:digit:]]+" | grep -o -e "[^>]*$"))
- temperatures1=($(echo ${table1} | grep -Eo -e "class=\"t_0\">[^/]*" | grep -Eo -e ">[-[:digit:]]+" | grep -Eo -e "[-[:digit:]]+"))
- clouds1=($(echo ${table1} | grep -Eo -e "class=\"cc_0\"[^o]*" | grep -Eo -e "c[dn][[:digit:]]" | grep -Eo -e "[[:digit:]]+"))
- conditions1=($(echo ${table1} | grep -Eo -e "class=\"pr_0\"[^/]*" | grep -Eo -e "wp_[^\"_]*"))
- pressure1=($(echo ${table1} | grep -Eo -e "class=\"p_0\">[^/]*" | grep -Eo -e ">[-[:digit:]]+" | grep -Eo -e "[-[:digit:]]+"))
- if [ ${#dates1[1]} -eq 2 ] && [ ${dates1[1]:0:1} == ${dates1[3]:0:1} ]
- then
- dates1[1]=${dates1[3]}
- fi
- if [ ${#dates1[-1]} -eq 2 ] && [ ${dates1[-1]:0:1} == ${dates1[-3]:0:1} ]
- then
- dates1[-1]=${dates1[-3]}
- fi
- if [ ${#dates3[1]} -eq 2 ] && [ ${dates3[1]:0:1} == ${dates3[3]:0:1} ]
- then
- dates3[1]=${dates3[3]}
- fi
- if [ ${#dates3[-1]} -eq 2 ] && [ ${dates3[-1]:0:1} == ${dates3[-3]:0:1} ]
- then
- dates3[-1]=${dates3[-3]}
- fi
- if [ ${#dates6[1]} -eq 2 ] && [ ${dates6[1]:0:1} == ${dates6[3]:0:1} ]
- then
- dates6[1]=${dates6[3]}
- fi
- if [ ${#dates6[-1]} -eq 2 ] && [ ${dates6[-1]:0:1} == ${dates6[-3]:0:1} ]
- then
- dates6[-1]=${dates6[-3]}
- fi
- if [ ${#dates3[-1]} -eq 2 ]
- then
- k=1
- while [ ${#dates6[-k]} -eq 2 ]
- do
- k=$[$k+1]
- done
- if [ ${dates3[-1]:0:1} == ${dates6[-k]:0:1} ]
- then
- dates3[-1]=${dates6[-1]}
- fi
- fi
- if [ ${#dates1[-1]} -eq 2 ]
- then
- k=1
- while [ ${#dates3[-k]} -eq 2 ]
- do
- k=$[$k+1]
- done
- if [ ${dates1[-1]:0:1} == ${dates3[-k]:0:1} ]
- then
- dates1[-1]=${dates3[-1]}
- fi
- fi
- i=0
- j=0
- k=0
- while [ $j -lt ${#times1[@]} ]
- do
- forecast[$k]=$(printf '%s\t%s\t%s\t%s\t%s\t%s\n' "${dates1[i]} ${dates1[i+1]}" "${times1[j]}" "${temperatures1[j]}" "${clouds1[j]}" "${pressure1[j]}" "${conditions1[j+j]} ${conditions1[j+j+1]}")
- k=$[$k+1]
- j=$[$j+1]
- if [ ! -z ${times1[j]} ] && [ ${times1[j]} -lt ${times1[j-1]} ]
- then
- i=$[$i+2]
- fi
- done
- i=0
- j=0
- while [ $j -lt ${#times3[@]} ]
- do
- if [ ${dates3[i]} -gt ${dates1[-2]} ] && [ ${dates3[i+1]} == ${dates1[-1]} ]
- then
- break
- fi
- if [ ${dates3[i]} -eq ${dates1[-2]} ] && [ ${times3[j]} -gt ${times1[-1]} ]
- then
- break
- fi
- j=$[$j+1]
- if [ ! -z ${times3[j]} ] && [ ${times3[j]} -lt ${times3[j-1]} ]
- then
- i=$[$i+2]
- fi
- done
- while [ $j -lt ${#times3[@]} ]
- do
- forecast[$k]=$(printf '%s\t%s\t%s\t%s\t%s\t%s\n' "${dates3[i]} ${dates3[i+1]}" "${times3[j]}" "${temperatures3[j]}" "${clouds3[j]}" "${pressure3[j]}" "${conditions3[j+j]} ${conditions3[j+j+1]}")
- k=$[$k+1]
- j=$[$j+1]
- if [ ! -z ${times3[j]} ] && [ ${times3[j]} -lt ${times3[j-1]} ]
- then
- i=$[$i+2]
- fi
- done
- i=0
- j=0
- while [ $j -lt ${#times6[@]} ]
- do
- if [ ${dates6[i]} -gt ${dates3[-2]} ] && [ ${dates6[i+1]} == ${dates3[-1]} ]
- then
- break
- fi
- if [ ${dates6[i]} -eq ${dates3[-2]} ] && [ ${times6[j]} -gt ${times3[-1]} ]
- then
- break
- fi
- j=$[$j+1]
- if [ ! -z ${times6[j]} ] && [ ${times6[j]} -lt ${times6[j-1]} ]
- then
- i=$[$i+2]
- fi
- done
- while [ $j -lt ${#times6[@]} ]
- do
- forecast[$k]=$(printf '%s\t%s\t%s\t%s\t%s\t%s\n' "${dates6[i]} ${dates6[i+1]}" "${times6[j]}" "${temperatures6[j]}" "${clouds6[j]}" "${pressure6[j]}" "${conditions6[j+j]} ${conditions6[j+j+1]}")
- k=$[$k+1]
- j=$[$j+1]
- if [ ! -z ${times6[j]} ] && [ ${times6[j]} -lt ${times6[j-1]} ]
- then
- i=$[$i+2]
- fi
- done
- echo ${name}
- printf "%s\n" "${forecast[@]}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement