SHARE
TWEET

Bloo

a guest Nov 30th, 2015 387 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3.     Thread listing      (By Bloo),   1.12.2015
  4.     Thread listing and auto-archiving using 4Arhive's API,   8.11.2015
  5. */
  6.     /* main */
  7.     $beginTime = date('l jS \of F Y H:i:s');
  8.     date_default_timezone_set('Europe/Sofia');
  9.     ini_set('memory_limit', '-1');
  10.     ini_set('max_execution_time', '-1'); //43200 seconds = 30 minutes
  11.     set_time_limit('-1'); //3 hours max execution time
  12.     //error_reporting(0); //turn off error/warning/notice reporting
  13.    
  14.     parse_str(implode('&', array_slice($argv, 1)), $_GET);
  15.    
  16.     if( isset( $_GET["posts"] ) && is_numeric($_GET["posts"]) && $_GET["posts"] > 0 )
  17.         $postCountNeeded = $_GET["posts"];
  18.     else
  19.         $postCountNeeded = 10;
  20.    
  21.     if( isset( $_GET["board"] ) && $_GET["board"] > "" )
  22.         $boardToArchive = $_GET["board"];
  23.     else
  24.         $boardToArchive = "a";
  25.  
  26.     $imageCountNeeded = 140;
  27.     $order = "rand"; //asc desc rand
  28.    
  29.     echo "/* Begin time " . $beginTime . " */" .PHP_EOL;
  30.     exec("title $postCountNeeded  posts min, $order, ONLY $boardToArchive  board,  30mins. pause");
  31.     do{
  32.         echo parseThoughAllBoards().PHP_EOL;
  33.         echo date('H:i:s')." Pausing for 30 minutes.".PHP_EOL;
  34.         sleep(1800); //pause for 30minutes, repeat. = 1800
  35.     }while(true);
  36.    
  37.     echo "/* Begin time " . $beginTime . " */" .PHP_EOL;
  38.     echo "/* End time" . date('l jS \of F Y H:i:s'). " */" .PHP_EOL;
  39.  
  40.    
  41.     function parseThoughAllBoards()
  42.     {
  43.         global $postCountNeeded, $order, $boardToArchive;
  44.        
  45.         $boardJson = @file_get_contents('http://a.4cdn.org/boards.json');
  46.         $boardInformation = json_decode($boardJson);
  47.         $boardInfo = $boardInformation->boards;
  48.         $boardCount = count($boardInfo);
  49.        
  50.         if($order == "asc")
  51.             asort($boardInfo);
  52.        
  53.         if($order == "desc")
  54.            rsort($boardInfo);
  55.        
  56.         if($order == "rand")
  57.            shuffle($boardInfo);
  58.        
  59.         for ($boardi = 0; $boardi < $boardCount; $boardi++)
  60.         {
  61.             $boardID =  $boardInfo[$boardi]->board;
  62.            
  63.             //all archivable boards
  64.             if( $boardID == $boardToArchive )
  65.                
  66.             // removing all shitty or huge boards AND the NSFW ones from below
  67.             // 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"  
  68.             //   $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" )
  69.                
  70.                //all NSFW boards
  71.             //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" )
  72.             {
  73.                 echo "# $boardi / $boardCount  - $boardID".PHP_EOL;
  74.                 $archiveJson = @file_get_contents('http://a.4cdn.org/' . $boardID . '/archive.json');
  75.                 $archiveInformation = json_decode($archiveJson);
  76.                 $archivedCount =  count($archiveInformation);
  77.                
  78.                 for ($archiveI = 0; $archiveI < $archivedCount; $archiveI++)
  79.                 {
  80.                     $archivedThreadID = $archiveInformation[$archiveI];
  81.                     $threadJson = @file_get_contents('http://a.4cdn.org/' . $boardID . '/thread/' . $archivedThreadID. '.json');
  82.                     $threadInformation = json_decode($threadJson);
  83.                     $livePosts = $threadInformation->posts;
  84.                     $livePostCount = count($livePosts);
  85.                     /*
  86.                     $countOfImages = 0;
  87.                     for ($i = 0; $i < $livePostCount; $i++)
  88.                     {
  89.                         $livePost = $livePosts[$i];
  90.                                    
  91.                         if( isset($livePost->tim) && $livePost->ext != ".webm") {
  92.                             $countOfImages++;
  93.                         }
  94.                     }*/
  95.                
  96.                     if( $livePostCount > $postCountNeeded ) //  min 10posts, max 20 images in the post
  97.                     {
  98.                         $link = "http://boards.4chan.org/$boardID/thread/$archivedThreadID" ;
  99.                       //  echo "<a href=\"$link\">   \"$link\",   </a> <br>".PHP_EOL;
  100.                         //echo "\"$link\", /* $livePostCount posts, $countOfImages images */".PHP_EOL;
  101.                         echo date('H:i:s '). "   $link - $livePostCount posts ".PHP_EOL;
  102.                         postThread( $boardID, $archivedThreadID );
  103.                     }
  104.                    
  105.                 } //fetched and parsed all threads in that boards
  106.                
  107.             }//check if we will archive that board
  108.            
  109.         }// fetched and parsed all boards
  110.    
  111.     }
  112.  
  113.     function postThread( $boardID, $archivedThreadID ) {
  114.         $url = 'http://localhost/4archive/public/api/archive';
  115.         $data = array('board' => $boardID, 'id' => $archivedThreadID );
  116.  
  117.         $chLocal = curl_init();
  118.         curl_setopt($chLocal, CURLOPT_SSL_VERIFYPEER, false);
  119.         curl_setopt($chLocal, CURLOPT_URL, $url);
  120.         curl_setopt($chLocal, CURLOPT_TIMEOUT, 3600); //1 hour max timeout
  121.         curl_setopt($chLocal, CURLOPT_POST, TRUE);
  122.         curl_setopt($chLocal, CURLOPT_RETURNTRANSFER, TRUE);
  123.         curl_setopt($chLocal, CURLOPT_POSTFIELDS,  $data );
  124.         $replyLocal = curl_exec($chLocal);
  125.         curl_close($chLocal);
  126.         //$replyLocal = json_decode($replyLocal);
  127.        
  128.         //var_dump($replyLocal).PHP_EOL;
  129.         $replyLocal = str_replace( '{', '',$replyLocal);
  130.         $replyLocal = str_replace('}', '', $replyLocal);
  131.         $replyLocal = str_replace('"', ' ', $replyLocal);
  132.         echo  date('H:i:s'). "  \t" . $replyLocal.PHP_EOL;
  133.     }
  134.    
  135.    
  136. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top