LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-16-2006, 12:51 PM   #1
xmrkite
Member
 
Registered: Oct 2006
Location: California, USA
Distribution: Mint 16, Lubuntu 14.04, Mythbuntu 14.04, Kubuntu 13.10, Xubuntu 10.04
Posts: 554

Rep: Reputation: 30
How to wget a random file from a website, then use FEH to view it.


Hello,

What I want to do is have it so that I run wget and FEH (an image viewer) and each time they are run, a different, random image file is download with wget and run in feh.

Now here is the tricky part...the images are online and are cool Garfield comics. They are named according to the date. For example: http://images.ucomics.com/comics/ga/2006/ga061016.gif

As you can see, the year is the folder that the image lies in, and the filename is "ga" then two digit year, month, date then .gif

How would i create a script to randomly download just one image, then use feh to show that image?

Some of the years would start with 19 and some with 20, and i need to make sure i don't use dates like sep 31 or feb 29 (unless it's a leap year).

Any help would be great, even a point in the right direction is appreciated.

-Thanks
 
Old 10-16-2006, 04:22 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Here's an example of an download-and-display script: http://www.linuxquestions.org/questi...d.php?t=463192
So all you have to do is randomise the URI.

Code:
#!/bin/sh
doThis() { RAND=${RANDOM:0:4}; }
doThat() { doThis; [ $RAND -le 2800 ] && FILE=`date +'/%Y/qa/%y%m%d.gif' --date="$RAND days ago"` || doThat ; }
doThat &&FILE=" http://images.ucomics.com/comics/ga${FILE}"
/some/app "$FILE"
exit 0
Now you can use the $FILE variable with the fetcher to get the file and display it on your desktop or script it to save it with wget to a tempfile and display with your viewer.

Last edited by unSpawn; 10-16-2006 at 04:23 PM. Reason: One slash too far.
 
Old 10-17-2006, 07:09 AM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Here's a way to do it with perl:

Code:
#!/usr/bin/perl -w

use Date::Parse;
use Date::Format;

my $earliest = str2time("2006:01:01");
my $get_time = $earliest + int( rand() * (time() - $earliest ));
my $url = time2str("http://images.ucomics.com/comics/ga/%Y/ga%y%m%d.gif", $get_time);
system("feh", $url);
Notes:
  1. You can set the earliest date by modifying the 2006:01:01 to whatever is the earliest date for which a URL exists (YYYY MM DD format).
  2. feh is called on the URL directly. No need for wget first.
  3. Don't forget to chmod a+x the file before trying to run it.
  4. All your scripts are belong to us.
 
Old 10-17-2006, 01:26 PM   #4
xmrkite
Member
 
Registered: Oct 2006
Location: California, USA
Distribution: Mint 16, Lubuntu 14.04, Mythbuntu 14.04, Kubuntu 13.10, Xubuntu 10.04
Posts: 554

Original Poster
Rep: Reputation: 30
Hey guys, thanks for the help.

I was able to get it going nicely.
 
  


Reply

Tags
random, wget



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
wget through an authenticated website davee Linux - Networking 2 02-11-2009 04:57 AM
using wget to download all videos from a website fakie_flip Linux - Software 3 08-16-2006 05:02 AM
How to download web pages from a website using wget command Fond_of_Opensource Linux - Newbie 5 07-05-2006 09:50 AM
wget a random file on phone server sub_moa Programming 16 07-01-2005 05:56 PM
wget - retrieving one folder of website davidhayter Linux - Software 4 03-07-2005 08:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration