Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Thread listing (By Bloo), 1.12.2015
- Thread listing and auto-archiving using 4Arhive's API, 8.11.2015
- */
- /* main */
- $beginTime = date('l jS \of F Y H:i:s');
- date_default_timezone_set('Europe/Sofia');
- ini_set('memory_limit', '-1');
- ini_set('max_execution_time', '-1'); //43200 seconds = 30 minutes
- set_time_limit('-1'); //3 hours max execution time
- //error_reporting(0); //turn off error/warning/notice reporting
- parse_str(implode('&', array_slice($argv, 1)), $_GET);
- if( isset( $_GET["posts"] ) && is_numeric($_GET["posts"]) && $_GET["posts"] > 0 )
- $postCountNeeded = $_GET["posts"];
- else
- $postCountNeeded = 10;
- if( isset( $_GET["board"] ) && $_GET["board"] > "" )
- $boardToArchive = $_GET["board"];
- else
- $boardToArchive = "a";
- $imageCountNeeded = 140;
- $order = "rand"; //asc desc rand
- echo "/* Begin time " . $beginTime . " */" .PHP_EOL;
- exec("title $postCountNeeded posts min, $order, ONLY $boardToArchive board, 30mins. pause");
- do{
- echo parseThoughAllBoards().PHP_EOL;
- echo date('H:i:s')." Pausing for 30 minutes.".PHP_EOL;
- sleep(1800); //pause for 30minutes, repeat. = 1800
- }while(true);
- echo "/* Begin time " . $beginTime . " */" .PHP_EOL;
- echo "/* End time" . date('l jS \of F Y H:i:s'). " */" .PHP_EOL;
- function parseThoughAllBoards()
- {
- global $postCountNeeded, $order, $boardToArchive;
- $boardJson = @file_get_contents('http://a.4cdn.org/boards.json');
- $boardInformation = json_decode($boardJson);
- $boardInfo = $boardInformation->boards;
- $boardCount = count($boardInfo);
- if($order == "asc")
- asort($boardInfo);
- if($order == "desc")
- rsort($boardInfo);
- if($order == "rand")
- shuffle($boardInfo);
- for ($boardi = 0; $boardi < $boardCount; $boardi++)
- {
- $boardID = $boardInfo[$boardi]->board;
- //all archivable boards
- if( $boardID == $boardToArchive )
- // removing all shitty or huge boards AND the NSFW ones from below
- // if( $boardID != "f" && $boardID != "pol" && $boardID != "a" && $boardID != "k" && $boardID != "o" && $boardID != "mu" && $boardID != "v" && $boardID != "ck" && $boardID != "fit" && $boardID != "his" && $boardID != "int" && $boardID != "lit" && $boardID != "sci" && $boardID != "sp" && $boardID != "tg" && $boardID != "vp" && $boardID != "g" && $boardID != "vg"
- // $boardID != "s" && $boardID != "hc" && $boardID != "h" && $boardID != "d" && $boardID != "u" && $boardID != "aco" && $boardID != "y" && $boardID != "hm" && $boardID != "i" && $boardID != "e" && $boardID != "t" && $boardID != "hr" && $boardID != "lgbt" && $boardID != "c" && $boardID != "cgl" && $boardID != "cm" && $boardID != "soc" && $boardID != "r9k" )
- //all NSFW boards
- //if( $boardID == "s" || $boardID == "hc" || $boardID == "h" || $boardID == "d" || $boardID == "u" || $boardID == "aco" || $boardID == "y" || $boardID == "hm" || $boardID == "i" || $boardID == "e" || $boardID == "t" || $boardID == "hr" || $boardID == "lgbt" || $boardID == "c" || $boardID == "cgl" || $boardID == "cm" || $boardID == "soc" || $boardID == "r9k" )
- {
- echo "# $boardi / $boardCount - $boardID".PHP_EOL;
- $archiveJson = @file_get_contents('http://a.4cdn.org/' . $boardID . '/archive.json');
- $archiveInformation = json_decode($archiveJson);
- $archivedCount = count($archiveInformation);
- for ($archiveI = 0; $archiveI < $archivedCount; $archiveI++)
- {
- $archivedThreadID = $archiveInformation[$archiveI];
- $threadJson = @file_get_contents('http://a.4cdn.org/' . $boardID . '/thread/' . $archivedThreadID. '.json');
- $threadInformation = json_decode($threadJson);
- $livePosts = $threadInformation->posts;
- $livePostCount = count($livePosts);
- /*
- $countOfImages = 0;
- for ($i = 0; $i < $livePostCount; $i++)
- {
- $livePost = $livePosts[$i];
- if( isset($livePost->tim) && $livePost->ext != ".webm") {
- $countOfImages++;
- }
- }*/
- if( $livePostCount > $postCountNeeded ) // min 10posts, max 20 images in the post
- {
- $link = "http://boards.4chan.org/$boardID/thread/$archivedThreadID" ;
- // echo "<a href=\"$link\"> \"$link\", </a> <br>".PHP_EOL;
- //echo "\"$link\", /* $livePostCount posts, $countOfImages images */".PHP_EOL;
- echo date('H:i:s '). " $link - $livePostCount posts ".PHP_EOL;
- postThread( $boardID, $archivedThreadID );
- }
- } //fetched and parsed all threads in that boards
- }//check if we will archive that board
- }// fetched and parsed all boards
- }
- function postThread( $boardID, $archivedThreadID ) {
- $url = 'http://localhost/4archive/public/api/archive';
- $data = array('board' => $boardID, 'id' => $archivedThreadID );
- $chLocal = curl_init();
- curl_setopt($chLocal, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($chLocal, CURLOPT_URL, $url);
- curl_setopt($chLocal, CURLOPT_TIMEOUT, 3600); //1 hour max timeout
- curl_setopt($chLocal, CURLOPT_POST, TRUE);
- curl_setopt($chLocal, CURLOPT_RETURNTRANSFER, TRUE);
- curl_setopt($chLocal, CURLOPT_POSTFIELDS, $data );
- $replyLocal = curl_exec($chLocal);
- curl_close($chLocal);
- //$replyLocal = json_decode($replyLocal);
- //var_dump($replyLocal).PHP_EOL;
- $replyLocal = str_replace( '{', '',$replyLocal);
- $replyLocal = str_replace('}', '', $replyLocal);
- $replyLocal = str_replace('"', ' ', $replyLocal);
- echo date('H:i:s'). " \t" . $replyLocal.PHP_EOL;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement