форум вебмастероff на AlfaSpace.NET |
Ubuntu и Linux
|реактивный бесплатный хостинг
| Киноклуб. ВСЁ БЕСПЛАТНО!
база знаний хостинга
|
правила форума
| Начало ° Ответить ° Статистика ° Опрос ° Регистрация ° Поиск ° FAQ ° |
| Форум вебмастеров на AlfaSpace.NET / Болтовня / Граббер цитат топа бездны bash.org.ru |
| Автор | Сообщение |
| Константин TorrentMaster 3497 |
# Дата: 10 Ноя 2007 23:42 Собственно сваял на коленке - граббер цитат из топа бездны с башорга, как наиболее вероятного источника встретить смешную цитату. Граббер состоит из двух скриптов - непосредственно граббера и просмотровщика. База данных не используется. Все хранится в файлах. Принцип работы граббера: -запускается по расписанию 1 раз в n минут, собирая цитаты со страницы bash.org.ru/abysstop -если цитата отсутствует в базе, то она добавляется, если присутствует, для нее обновляется рейтинг -цитаты старше 4х дней удаляются Принцип работы просмотровщика: -читает цитаты, проверяет количество их просмотров, если оно более 8, не выводит, иначедобавляет к результату -перед выводом сортирует по времени добавления, т.е. новые цитаты будут вначале -добавляет к каждой цитате +1 просмотр (чтобы старые цитаты через 8 просмотров перестали показываться, это кстати означает, что использовать просмотровщик должен один человек, если настройка максимального числа просмотров не будет убрана или увеличена) для работы граббера необходимо: - хостинг с php5 (можно php4, но тогда функцию file_put_contents вам придется написать самим) safemode=off - cron - для запуска граббера по расписанию - файлы abyss.php (просмотровщик), bash.php (сам граббер), bashnum.txt (номер последней добавленной цитаты) - с доступом на запись, директирия bash с доступом на запись Архив со всем необходимым для работы: http://dslnet.ru/tcount/cache/ac/bash.grubber.tar |
| SpiriTzzz Темный джедай 1382 |
# Дата: 11 Ноя 2007 00:57 вы маньяк, батенька ![]() |
| Константин TorrentMaster 3497 |
# Дата: 11 Ноя 2007 15:34 SpiriTzzz Ага, я знаю
Небольшой апдейт: 1. Если 8 (9) просмотров для цитаты много, то меняем в abyss.php в строке if ($views>8) continue; значение 8 на 1,2,3 или 4 2.Если хранить цитаты за 4 дня не хочется, то меняем в bash.php в строке if ((filemtime('./bash/'.$file))<(time()-3600*24*4)) значение 4 на 1,2 или 3 - тогда будут храниться только цитаты за 1,2 или 3 дня |
| persei Участник 482 |
# Дата: 11 Ноя 2007 19:21 У мну знакомый на до диезе сбацал. Составляет архив, могет его регулярно синкать. Поделиться? ![]() |
| acsid Alfa Guru 2410 |
# Дата: 11 Ноя 2007 19:51 ° Поправил: acsid persei поделись) Константин молодец, спасиба .. никак не могу настроить крон под свои скрипты.Посмотрю на твоём примере ![]() |
| Константин TorrentMaster 3497 |
# Дата: 11 Ноя 2007 20:12 persei Давай )) |
| Константин TorrentMaster 3497 |
# Дата: 11 Ноя 2007 20:14 ° Поправил: Константин acsid локально: crontab -l > ./crontab.txt редактируем crontab.txt, добавляя /10 * * * * /usr/local/bin/php /pathtobashphp/bash.php > /dev/null сохраняем затем crontab ./crontab.txt собственно все удаленно: если у тебя нет где-то крона, то его можно на месяц получить здесь: http://cronjob.ru/ |
| acsid Alfa Guru 2410 |
# Дата: 11 Ноя 2007 20:31 ° Поправил: acsid » Константин удаленно:
если у тебя нет где-то крона, то его можно на месяц получить здесь: cronjob.ru/ Интересная информация, возьму на вооружение. ![]() |
| WarGot Per aspera ad astra 1948 |
# Дата: 12 Ноя 2007 04:33 Эх не зря я Defa на баш подсадил -) |
| Константин TorrentMaster 3497 |
# Дата: 12 Ноя 2007 10:32 WarGot ![]() |
| Roler USA Hater 1301 |
# Дата: 12 Ноя 2007 11:41 Огромное спасибо, поробую дописать чтобы граббил ещё и с главной, иногда хорошие цитаты идут прямо туда ![]() |
| Константин TorrentMaster 3497 |
# Дата: 12 Ноя 2007 13:33 ° Поправил: Константин Roler Я возможно тоже попробую сделать сбор цитат и с главной, но там достаточно редко появляется что-то новое и еще реже смешное (хотя исключения есть). А пока текущая версия кода (несколько более компактный вывод заголовка, ручная очистка, больше статистики, меньшее число просмотров до того как цитата станет невидима, все оптимизировано для просмотра через стандартный браузер телефона Sony Ericsson K790i (ну и остальных моделей с 320х240 экраном)): bash.php
<?php
set_time_limit(16);
//delete old citates firstly
$dir = "./bash/";
$count=0;
$cnt=0;
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if (($file=='.')||($file=='..')) continue;
if ((filemtime('./bash/'.$file))<(time()-5400*24))
{
unlink('./bash/'.$file);
continue;
}
$src=file_get_contents('./bash/'.$file);
$srce=explode("<br>\n",$src);
$views=$srce[1];
$cnt++;
if ($views<5) $count++;
}
closedir($dh);
}
}
//load new
$cmd = "wget --tries=1 -q -O - http://bash.o
rg.ru/abysstop";
exec($cmd, $outputt);
$output='';
foreach ($outputt as $line)
{
$output.=$line;
}
$offset=0;
$result='';
$grubbed=0;
$curcount=0+file_get_contents('./bashnum.txt');
while (($dpos=strpos($output,'<div class="vote">',$offset))>0)
{
$offset=$dpos;
$numpos=strpos($output,'<b>',$offset);
$offset=$numpos;
$number=substr($output,$numpos+3,2);
if ($number[1]==':') $number=substr($number,0,1);
$ratpos=strpos($output,'<span>',$offset);
$offset=$ratpos;
$rating=substr($output,$ratpos+6,2);
if ($rating[1]=='<') $rating=substr($rating,0,1);
$datpos=strpos($output,'добавлена ',$offset);
$offset=$datpos;
$date=substr($output,$datpos+10,16);
$datemd5=md5($date);
$citpos=strpos($output,'<div>',$offset);
$offset=$citpos;
$citlen=strpos($output,'</div>',$offset)-$citpos-5;
$citate=substr($output,$citpos+5,$citlen);
$citate=str_replace("<br><br>","<br>",$citate);
$citate=str_replace("<br><br>","<br>",$citate);
if (file_exists('./bash/'.$datemd5))
{//only update rating and save views untouched
$src=file_get_contents('./bash/'.$datemd5);
$srce=explode("<br>\n",$src);
$cnumber=$srce[0];
$views=$srce[1];
//$rating=$srce[2];
//$date=$srce[3];
//$citate=$srce[4];
file_put_contents('./bash/'.$datemd5, $cnumber."<br>\n".$views."<br>\n".$r
ating."<br>\n".$date."<br>\n".$citate."<br>\n");
}
else
{//save citate and rating + count of views
$grubbed++;
$curcount++;
file_put_contents('./bash/'.$datemd5,"$curcount<br>\n0<br>\n".$rating."<br
>\n".$date."<br>\n".$citate."<br>\n");
}
}
file_put_contents('./bashnum.txt',$curcount);
die("Visible/total citations:$count/$cnt<br>\nLast citation number: $curcount<b
r>\nCitations grubbed: $grubbed<br>\nCitations updated: ".(25-$grubbed)."<br>\n
<
a href=abyss.php>View</a> <a href=abyss.php?clear=1>Clear</a>");
?>
abyss.php
<?php
set_time_limit(16);
$dir = "./bash/";
$clear=isset($_GET['clear']);
$count=0;
$cnt=0;
$resmas=array();
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if (($file=='.')||($file=='..')) continue;
$src=file_get_contents('./bash/'.$file);
$srce=explode("<br>\n",$src);
$citnumb=$srce[0];
$views=$srce[1];
$viewss=$views+1;
$cnt++;
if ($views>4) continue;
$count++;
if ($clear)
{//clear all with views>0
if ($views>0) $viewss=5;
else $viewss=0;
$count--;
}
$rating=$srce[2];
$date=$srce[3];
$citate=$srce[4];
file_put_contents('./bash/'.$file, "$citnumb<br>\n".$viewss."<br>\n".$r
ating."<br>\n".$date."<br>\n".$citate."<br>\n");
if (!$clear) $resmas[$citnumb]='('.$citnumb.') <u>R:'.$rating.'['.$date
.']V:'.(1+$views)."</u><br>\n".$citate."<br>\n<hr>\n";
}
closedir($dh);
}
}
$resulthtml='<font size=2><a href=http://bash.org.ru>main</a> <a href=http://ba
sh.org.ru/abysstop>abysstop</a> <a href=http://bash.org.ru/abyss>abyss</a> [V:'
.
$count.'/'.$cnt.']<hr>';
if (!$clear)
{
krsort($resmas);
$count=0;
foreach($resmas as $key => $val)
{
$count++;
$resulthtml.="<b>$count.</b>$val";
}
$resulthtml.='<a href=abyss.php?clear=1>clear</a> <a href=bash.php>get new</a><
hr>';
}
else
{
$resulthtml.='Done<br><a href=abyss.php>view</a> <a href=bash.php>get new</a><h
r>';
}
$resulthtml.='<font size=1><center>(c) Konstantin: <a href=http://avangard-trac
ker.alfamoon.com>avangard-tracker.alfamoon.com</a> & <a href=http://dslnet.ru>d
s
lnet.ru</a></center></font>';
die($resulthtml);
?>
|
| Александр Леонидович 1093 |
# Дата: 12 Ноя 2007 16:15 ре Раньше когда с ЛОРа цитаты были - было и правда смешно. А сейчас попса пошла дко появляется что-то новое и еще реже смешное (хотя исключения есть). ![]() |
| Константин TorrentMaster 3497 |
# Дата: 12 Ноя 2007 23:29 ° Поправил: Константин Александр К сожалению это так
--- очередной апдейт: скрипт научился грабить цитаты и с главной (берет последние 25); цитаты с главной не удаляются 8 дней, поэтому не появятся повторно в выводе скрипта; если цитата из топа бездны была зааппрувлена на главную, она получит статус "цитата с главной" и не будет удалена из базы 8 дней, т.о. не будет с 95% вероятностью заново показана (напомню что цитата из бездны может быть показана повторно, если она будет удалена, а затем повторно загружена из топа бездны через 2 дня)
bash.php
<?php
set_time_limit(16);
//delete old citates firstly
$dir = "./bash/";
$count=0;
$cnt=0;
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if (($file=='.')||($file=='..')) continue;
$src=file_get_contents('./bash/'.$file);
$srce=explode("<br>\n",$src);
$fmain=$srce[5];
$views=$srce[1];
if ((filemtime('./bash/'.$file))<(time()-7200*24))
{ //$fmain==1 => untouchable
if (!($fmain==1)) {unlink('./bash/'.$file); continue;}
elseif ((filemtime('./bash/'.$file))<(time()-3600*24*8)) {unlink('./b
ash/'.$file); continue;}
}
$cnt++;
if ($views<5) $count++;
}
closedir($dh);
}
}
//load new from abysstop
$cmd = "wget --tries=1 -q -O - http://bash.o
rg.ru/abysstop";
exec($cmd, $outputt);
$output='';
foreach ($outputt as $line)
{
$output.=$line;
}
$offset=0;
$grubbed=0;
$curcount=0+file_get_contents('./bashnum.txt');
while (($dpos=strpos($output,'<div class="vote">',$offset))>0)
{
$offset=$dpos;
$numpos=strpos($output,'<b>',$offset);
$offset=$numpos;
$ratpos=strpos($output,'<span>',$offset);
$offset=$ratpos;
$rating=substr($output,$ratpos+6,2);
if ($rating[1]=='<') $rating=substr($rating,0,1);
$datpos=strpos($output,'добавлена ',$offset);
$offset=$datpos;
$date=substr($output,$datpos+10,16);
$datemd5=md5($date);
$citpos=strpos($output,'<div>',$offset);
$offset=$citpos;
$citlen=strpos($output,'</div>',$offset)-$citpos-5;
$citate=substr($output,$citpos+5,$citlen);
$citate=str_replace("<br><br>","<br>",$citate);
$citate=str_replace("<br><br>","<br>",$citate);
if (file_exists('./bash/'.$datemd5))
{//only update rating and save views untouched
$src=file_get_contents('./bash/'.$datemd5);
$srce=explode("<br>\n",$src);
$cnumber=$srce[0];
$views=$srce[1];
file_put_contents('./bash/'.$datemd5, $cnumber."<br>\n".$views."<br>\n".$r
ating."<br>\n".$date."<br>\n".$citate."<br>\n");
}
else
{//save citate and rating + count of views
$grubbed++;
$curcount++;
file_put_contents('./bash/'.$datemd5,"$curcount<br>\n0<br>\n".$rating."<br
>\n".$date."<br>\n".$citate."<br>\n");
}
}
//get last 25 from main page
$cmd = "wget --tries=1 -q -O - [url=http://bash.org.ru";]http://bash.org.ru";[/
url]
exec($cmd, $outputt);
$output='';
foreach ($outputt as $line)
{
$output.=$line;
}
$offset=0;
$grubbed1=0;
$cnn=0;
while (($dpos=strpos($output,'<div class="vote">',$offset))>0)
{
$cnn++;
if ($cnn>25) break;//grub only 25 first citations from main page
$offset=$dpos;
$numpos=strpos($output,'<a href="/quote/',$offset);
$offset=$numpos;
$ratpos=strpos($output,'<span>',$offset);
$offset=$ratpos;
$rating=substr($output,$ratpos+6,2);
$datpos=strpos($output,', ',$offset);
$offset=$datpos;
$date=substr($output,$datpos+2,16);
$datemd5=md5($date);
$citpos=strpos($output,'<div>',$offset);
$offset=$citpos;
$citlen=strpos($output,'</div>',$offset)-$citpos-5;
$citate=substr($output,$citpos+5,$citlen);
$citate=str_replace("<br><br>","<br>",$citate);
$citate=str_replace("<br><br>","<br>",$citate);
if (file_exists('./bash/'.$datemd5))
{//only update rating and save views untouched
$src=file_get_contents('./bash/'.$datemd5);
$srce=explode("<br>\n",$src);
$cnumber=$srce[0];
$views=$srce[1];
file_put_contents('./bash/'.$datemd5, $cnumber."<br>\n".$views."<br>\n".$r
ating."<br>\n".$date."<br>\n".$citate."<br>\n1");
}
else
{//save citate and rating + count of views
$grubbed1++;
$curcount++;
file_put_contents('./bash/'.$datemd5,"$curcount<br>\n0<br>\n".$rating."<br
>\n".$date."<br>\n".$citate."<br>\n1");
}
}
$count=$count+$grubbed+$grubbed1;
$cnt=$cnt+$grubbed+$grubbed1;
file_put_contents('./bashnum.txt',$curcount);
die("Visible/total citations:$count/$cnt<br>\nLast citation number: $curcount<b
r>\nGrubbed from abysstop: $grubbed<br>\nGrubbed from main: $grubbed1<br>\nCita
t
ions updated: ".(25-$grubbed).'+'.(25-$grubbed1)."<br>\n<a href=abyss.php>View<
/
a> <a href=abyss.php?clear=1>Clear</a>");
?>
abyss.php:
<?php
set_time_limit(16);
$dir = "./bash/";
$clear=isset($_GET['clear']);
$count=0;
$cnt=0;
$resmas=array();
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if (($file=='.')||($file=='..')) continue;
$src=file_get_contents('./bash/'.$file);
$srce=explode("<br>\n",$src);
$citnumb=$srce[0];
$views=$srce[1];
$viewss=$views+1;
$cnt++;
if ($views>4) continue;
$count++;
if ($clear)
{//clear all with views>0
if ($views>0) $viewss=5;
else $viewss=0;
$count--;
}
$rating=$srce[2];
$date=$srce[3];
$citate=$srce[4];
$fmain=$srce[5];
file_put_contents('./bash/'.$file, "$citnumb<br>\n".$viewss."<br>\n".$r
ating."<br>\n".$date."<br>\n".$citate."<br>\n$fmain");
if (!$clear) $resmas[$citnumb]='('.$citnumb.') <u>R:'.$rating.'['.$date
.']V:'.(1+$views)."</u><br>\n".$citate."<br>\n<hr>\n";
}
closedir($dh);
}
}
$resulthtml='<font size=2><a href=http://bash.org.ru>main</a> <a href=http://ba
sh.org.ru/abysstop>abysstop</a> <a href=http://bash.org.ru/abyss>abyss</a> [V:'
.
$count.'/'.$cnt.']<hr>';
if (!$clear)
{
krsort($resmas);
$count=0;
foreach($resmas as $key => $val)
{
$count++;
$resulthtml.="<b>$count.</b>$val";
}
$resulthtml.='<a href=abyss.php?clear=1>clear</a> <a href=bash.php>get new</a><
hr>';
}
else
{
$resulthtml.='Done<br><a href=abyss.php>view</a> <a href=bash.php>get new</a><h
r>';
}
$resulthtml.='<font size=1><center>(c) Konstantin: <a href=http://avangard-trac
ker.alfamoon.com>avangard-tracker.alfamoon.com</a> & <a href=http://dslnet.ru>d
s
lnet.ru</a></center></font>';
die($resulthtml);
?>
Известные баги: некорректное сохранение рейтинга для цитат с главной. Исправлять сейчас уже лень, вероятно позже - я так полагаю там одну строку поправить )) |
| persei Участник 482 |
# Дата: 13 Ноя 2007 08:35 http://mods.mirandaim.ru/files/BorReader.exe http://chaoslab.info/files/BorReader.exe (там же последний нет сендер) естесно нужен .NET 2.0 |
|
Powered by miniBB forum software © 2001-2008
Powered by miniBB-gzipper. Original size:49772, gzipped size:12801 |