Skip to content

Instantly share code, notes, and snippets.

@piedcipher
Last active December 30, 2017 10:54
Show Gist options
  • Save piedcipher/c98d63ceea994967ed2de98f3d41668e to your computer and use it in GitHub Desktop.
Save piedcipher/c98d63ceea994967ed2de98f3d41668e to your computer and use it in GitHub Desktop.
iWallE App (PHP File) | CodeWord
<?php
$curl = curl_init();
$subreddit = $argv[1];
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.imgur.com/3/gallery/r/$subreddit",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"authorization: Client-ID {{PROVIDE_CLIENT-ID_HERE}}"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
$response = json_decode($response);
print_r($response);
$count = count($response->data);
$random = rand(0, $count);
if($response->data[$random]->type == "image/png"){
$ext = "png";
} else {
$ext = "jpg";
}
$link = $response->data[$random]->link;
$wallpaper = file_get_contents($link);
file_put_contents("PROVIDE_PATH_HERE.$ext", $wallpaper);
$path = "file://PROVIDE_PATH_HERE.$ext";
shell_exec("gsettings set org.gnome.desktop.background picture-uri $path");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment