PDA

View Full Version : Software to download jpeg from internet every 5 mins then rename?


tim
20th of April 2010 (Tue), 00:58
I'm trying to work out traffic patterns, so I can work out when I need to be in the car by to avoid traffic. I want to download images from four set URLs every 5 minutes, for a day or three, and have it rename the images in some way so I can tell which camera and what time the image is from.

I can write a piece of software to do this in maybe an hour, but if there's anything around I can download that'd be way easier. Anyone know of anything like that?

primoz
21st of April 2010 (Wed), 02:19
Windows? Good luck. Unix (Mac included)? Piece of cake with short shell or perl script.

tim
21st of April 2010 (Wed), 02:32
I don't really do perl, though I have in the past. I could knock it up in Java easy as, or PHP with a bit more thought.

int2str
21st of April 2010 (Wed), 02:50
So it's on Windows?
Are the images a directly accessible URL? As in, it's not an embedded image but one you can directly link to?

If so, do this:
1. Install Cygwin (http://cygwin.org)
2. Start cygwin and write a shell script as following:

#!/bin/sh

while :
do
wget "http://www.dot.ca.gov/dist11/d11tmc/sdmap/realtdata/realtmap.jpg"
sleep 600
done

3. Execute script

This will download the image at the URL every 10 minutes. You can add more wget commands as necessary.

tim
21st of April 2010 (Wed), 02:58
That's pretty stupidly simple, thanks! How about renaming it based on the time? I don't want to overwrite the old files and would love a timestamp.

I might just run it on my unix box at work, it's on anyway.

primoz
21st of April 2010 (Wed), 03:25
Just add following before "sleep 600":

timestamp=`date "+%Y%m%d%H%M"`
mv realtmap.jpg $timestamp.jpg

PS: this would work on Unix, but I really have no experience with Cygwin on Windows.

PS #2: This would give you file 201004211025.jpg (for 21st of April 2010 at 10:25).

tim
21st of April 2010 (Wed), 03:56
Perfect, thank you!

For bonus points how would I add 17 hours to the timestamp, so I can run it on my server in the US but get it in local time? Feel free to tell me to go chase parked cars ;)

primoz
21st of April 2010 (Wed), 04:10
Now you are pushing... so go chase parked cars :P

Ok seriouslly... Whole thing would look like this then:


#!/bin/sh

while :
do
wget "http://www.dot.ca.gov/dist11/d11tmc/sdmap/realtdata/realtmap.jpg"
datestamp=`date "+%Y%m%d"`
hour=`date "+%H"`
minute=`date "+%M"`
hour17=`expr $hour + 17`
mv realtmap.jpg $datestamp$hour17$minute.jpg
sleep 600
done


Edit: Shi*** this won't do really good, since your day would be from 17:00 till 41:59, which probably wouldn't make much sense

tim
21st of April 2010 (Wed), 04:18
Haha, Java's time zone aware so it'd be trivial! No matter if the timestamp's not perfect, one of the images I need has a timestamp written on it so that'll give me all I need.

Thanks again for your help, it's running on my hosted server and will grab images for me until stop it... or get kicked off the server for inappropriate use! Maybe i'll run it at work... :)