Last active
May 15, 2022 09:59
-
-
Save b00f/0227276226a255300cc094d4712178ac to your computer and use it in GitHub Desktop.
A perl script to set National Geographic (photo of the day) as wallpaper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use LWP::Simple; | |
my $url = "https://www.nationalgeographic.com/photography/photo-of-the-day"; | |
my $desc_regex = qr/description\" content=\"(.*?)\"/mp; | |
my $url_regex = qr/twitter:image:src\" content=\"(.*?)\"/mp; | |
my $path_regex = qr/[^\/]+$/mp; | |
my $str = get("https://www.nationalgeographic.com/photography/photo-of-the-day") or die "no such luck 1\n"; | |
my $str2 = $str; | |
if ( $str =~ /$url_regex/g ) { | |
my $path = ${1}; | |
if ( $path =~ /$path_regex/g ) { | |
my $filename = ${^MATCH}; | |
my $imagefile = sprintf("%s/Pictures/Wallpapers/NatGeo/%s", $ENV{'HOME'}, ${filename}); | |
open (fh, ">", $imagefile); | |
print $path . "\n"; | |
my $data = get($path) or die "no such luck 2\n"; | |
print fh $data; | |
if ( $str2 =~ /$desc_regex/g ) { | |
my $descfile = sprintf("%s/Pictures/Wallpapers/NatGeo/%s.txt", $ENV{'HOME'}, ${filename}); | |
open (fh, ">", $descfile); | |
print fh $path; | |
print fh "\n"; | |
print fh ${1}; | |
print ${1} . "\n"; | |
} | |
system(sprintf("gsettings set org.gnome.desktop.background picture-uri-dark \"file://%s\"", $imagefile)); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment