Skip to content

Instantly share code, notes, and snippets.

@RSquaredSoftware
Created November 12, 2013 03:22
Show Gist options
  • Save RSquaredSoftware/7424941 to your computer and use it in GitHub Desktop.
Save RSquaredSoftware/7424941 to your computer and use it in GitHub Desktop.
<?php
function grab_image($url,$saveto){
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$raw=curl_exec($ch);
curl_close ($ch);
if(file_exists($saveto)){
unlink($saveto);
}
$fp = fopen($saveto,'x');
fwrite($fp, $raw);
fclose($fp);
}
$reddits = array("pics", "4chan", "funny", "sexy", "WTF", "imgoingtohellforthis", "iiiiiiitttttttttttt", "aww", "fffffffuuuuuuuuuuuu", "gifs", "gaming", "cringe", "cringepics", "nsfw",);
foreach ($reddits as $reddit) {
$url = "http://reddit.com/r/$reddit/.json?limit=100";
$raw = json_decode(file_get_contents($url));
foreach($raw->data->children as $n) {
if(preg_match('(jpg$|gif$|png$)', $n->data->url, $match) && ($n->data->score >= 700)) {
grab_image($n->data->url, "/var/www/pic/media/staging/".$n->data->id . substr($n->data->url, -5));
echo "Saved: " . $n->data->url . "\n";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment