Skip to content

Instantly share code, notes, and snippets.

@StSav012
Last active October 30, 2017 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StSav012/bb52bfc292ddfe5b3042ae2b50e4c767 to your computer and use it in GitHub Desktop.
Save StSav012/bb52bfc292ddfe5b3042ae2b50e4c767 to your computer and use it in GitHub Desktop.
rp5 site parser
lang="ru"
place="Нижний Новгород"
code=5797
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:]]+"))
pressure6=($(echo ${table6} | grep -Eo -e "class=\"p_0\">[^/]*" | grep -Eo -e ">[-[:digit:]]+" | grep -Eo -e "[-[:digit:]]+"))
k=0
while read -r line
do
conditions6[$k]=$line
k=$[$k+1]
done < <(echo ${table6} | grep -Pzo "t\_fraction(.|\n)*underlineRow" | grep -Eao -e "div class=\"pr_0\" onmouseover=[^=]+" | grep -Po -e "this , \'[^\']+" | grep -Po -e "[^\']+$")
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:]]+"))
pressure3=($(echo ${table3} | grep -Eo -e "class=\"p_0\">[^/]*" | grep -Eo -e ">[-[:digit:]]+" | grep -Eo -e "[-[:digit:]]+"))
k=0
while read -r line
do
conditions3[$k]=$line
k=$[$k+1]
done < <(echo ${table3} | grep -Pzo "t\_fraction(.|\n)*underlineRow" | grep -Eao -e "div class=\"pr_0\" onmouseover=[^=]+" | grep -Po -e "this , \'[^\']+" | grep -Po -e "[^\']+$")
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:]]+"))
pressure1=($(echo ${table1} | grep -Eo -e "class=\"p_0\">[^/]*" | grep -Eo -e ">[-[:digit:]]+" | grep -Eo -e "[-[:digit:]]+"))
k=0
while read -r line
do
conditions1[$k]=$line
k=$[$k+1]
done < <(echo ${table1} | grep -Pzo "t\_fraction(.|\n)*underlineRow" | grep -Eao -e "div class=\"pr_0\" onmouseover=[^=]+" | grep -Po -e "this , \'[^\']+" | grep -Po -e "[^\']+$")
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
echo ${name}
while [ $j -lt ${#times1[@]} ]
do
firstconditions=(${conditions1[j+j]})
secondconditions=(${conditions1[j+j+1]})
otherconditions=" "
h=0
while [ $h -lt ${#firstconditions[@]} ] && [ $h -lt ${#secondconditions[@]} ] && [ ${firstconditions[h]} == ${secondconditions[h]} ]
do
h=$[$h+1]
done
while [ $h -lt ${#secondconditions[@]} ] && [ ! -z ${secondconditions[h]} ]
do
otherconditions=${otherconditions}" "${secondconditions[h]}
h=$[$h+1]
done
printf '%s\t%s %s\t%s %s %s\n' "${dates1[i]} ${dates1[i+1]}" "${times1[j]}" "${temperatures1[j]}" "${clouds1[j]}" "${pressure1[j]}" "${conditions1[j+j]}${otherconditions}"
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
firstconditions=(${conditions3[j+j]})
secondconditions=(${conditions3[j+j+1]})
otherconditions=" "
h=0
while [ $h -lt ${#firstconditions[@]} ] && [ $h -lt ${#secondconditions[@]} ] && [ ${firstconditions[h]} == ${secondconditions[h]} ]
do
h=$[$h+1]
done
while [ $h -lt ${#secondconditions[@]} ] && [ ! -z ${secondconditions[h]} ]
do
otherconditions=${otherconditions}" "${secondconditions[h]}
h=$[$h+1]
done
printf '%s\t%s %s\t%s %s %s\n' "${dates3[i]} ${dates3[i+1]}" "${times3[j]}" "${temperatures3[j]}" "${clouds3[j]}" "${pressure3[j]}" "${conditions3[j+j]}${otherconditions}"
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
firstconditions=(${conditions6[j+j]})
secondconditions=(${conditions6[j+j+1]})
otherconditions=" "
k=0
while [ $k -lt ${#firstconditions[@]} ] && [ $k -lt ${#secondconditions[@]} ] && [ ${firstconditions[k]} == ${secondconditions[k]} ]
do
k=$[$k+1]
done
while [ $k -lt ${#secondconditions[@]} ] && [ ! -z ${secondconditions[k]} ]
do
otherconditions=${otherconditions}" "${secondconditions[k]}
k=$[$k+1]
done
printf '%s\t%s %s\t%s %s %s\n' "${dates6[i]} ${dates6[i+1]}" "${times6[j]}" "${temperatures6[j]}" "${clouds6[j]}" "${pressure6[j]}" "${conditions6[j+j]}${otherconditions}"
j=$[$j+1]
if [ ! -z ${times6[j]} ] && [ ${times6[j]} -lt ${times6[j-1]} ]
then
i=$[$i+2]
fi
done
@StSav012
Copy link
Author

Obsolete, will not upgrade soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment