Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ALL);
- date_default_timezone_set('UTC');
- $entries = array();
- function get($url)
- {
- $filename = 'c/'.md5($url).'txt';
- if(!file_exists($filename))
- {
- $response = file_get_contents($url);
- file_put_contents($filename, $response);
- sleep(2.1);
- }
- else
- {
- $response = file_get_contents($filename);
- }
- return $response;
- }
- $subs = explode(',', $_GET['sub']);
- $lh = fopen('log.txt', 'w+');
- foreach($subs as $sub)
- {
- if(file_exists('images/'.$sub))
- continue;
- if(!is_dir('images/'.$sub))
- {
- mkdir('images/'.$sub);
- chmod('images/'.$sub, 0777);
- }
- $after = '';
- $pages = 10;
- for($p = 0; $p < $pages; $p++)
- {
- fwrite($lh, $sub.' '.$p."\n");
- $url = 'http://reddit.com/r/'.$sub.'/top/.json?sort=top&count=25&after='.$after.'&t=all';
- echo $url."\n";
- $data = json_decode(get($url), true);
- $data = $data['data']['children'];
- for($i = 0; $i < count($data); $i++)
- {
- if($i == count($data) - 1)
- {
- $after = 't3_'.$item['id'];
- }
- $item = $data[$i]['data'];
- $thumbnail_url = $item['thumbnail'];
- if(!stristr($thumbnail_url, 'http://'))
- continue;
- $fname = 'images/'.$sub.'/'.$item['id'].'.jpg';
- if(!file_exists($fname))
- file_put_contents($fname, file_get_contents($thumbnail_url));
- }
- }
- }
- fclose($lh);
- ?>
Add Comment
Please, Sign In to add comment