вторник, 3 марта 2009 г.

Получаем телепрограмму

Скрипт скачки телепрограммы tv.sh
#!/bin/bash
if [ -f "/home/simpson/scripts/tv/index.html"]
then
rm ~/scripts/tv/index.html
# rm ~/scripts/tv/tv.html - если вывод в файрфокс
fi
wget -E -P ~/scripts/tv http://tv.yandex.ru

php ~/scripts/tv/tv.php
for chanal in Первый Россия Центр НТВ Культура Спорт ТНТ Домашний РЕН СТС ТВ3 ДТВ Звезда
do
echo $chanal
cat ~/scripts/tv/tv.txt | grep $chanal | grep `date +%H`| cut -d = -f 1
#Для удобства, можно в файрфокс вывести
#echo "<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=utf-8'>"
#echo "
" $chanal "
"
#cat /home/simpson/scripts/tv/tv.txt | grep $chanal | cut -d = -f 1
#echo "
"

#done > ~/scripts/tv/tv.html
#firefox ~/scripts/tv/tv.html

done



Скрипт обработки скаченный программы, и вывода результата в файл tv.php

).*(?=<\/span>)/', $file_array, $matches3);
preg_match_all('/(?<=summary">).*(?=<\/span><span class="location")/', $file_array, $matches);
preg_match_all('/(?<=dtstart">[0-9][0-9][0-9][0-9][-][0-9][0-9][-][0-9][0-9][T]).*(?=:00\+)/', $file_array, $matches2);


for($i=0;$i<count($matches[0]);$i++)
{
$k[$matches3[0][$i]] = $i;
$mass[] = $matches[0][$i];

$mz[$i][$mass[$i]] = $matches2[0][$i];
$kanal[$matches3[0][$i]] = $mass;
}

$k = array_values(array_flip($k));
$qq = array_count_values($matches3[0]); //количество каждых значений масива каналов
$qq = array_values($qq);

for($j=0; $j<=count($qq);$j++) { for($o = 0; $o<=count($matches[0]);$o++) { if($o<=$qq[$j]) { $massiv[$k[$j]]= $kanal[$o]; } } } $file = fopen("/home/имя юзера/scripts/tv/tv.txt","w+"); for($ii=0; $ii<=count($matches[0]);$ii++) { $text = $text.$matches2[0][$ii]." - ".$matches[0][$ii]."=".$matches3[0][$ii]."//\n"; } $fw=fputs($file,$text); fclose($file); ?>
для зауска в консоле
~/scripts/tv/tv.sh
можно положить скрипт в ~/.gnome2/nautilus-scripts
сделать исполняемым
chmod +X ~/.gnome2/nautilus-scripts/tv.sh
либо кинуть в коньки:
~/.conky/scripts
в конфиге коньков(~/.conkyrc) добавить:
${execi 3600 ~/.conky/scripts/kurs.sh}

Комментариев нет: