# Help writing a cron job to get Flickr photos

**URL:** <https://www.ruby-forum.com/t/help-writing-a-cron-job-to-get-flickr-photos/84913>\
**Category:** Rails\
**Created:** [February 8, 2007, 5:10pm UTC](https://www.ruby-forum.com/t/help-writing-a-cron-job-to-get-flickr-photos/84913 "2007-02-08T17:10:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c2a13f/32.png) [@rph](https://www.ruby-forum.com/u/rph)\
**Post date:** [February 8, 2007, 5:10pm UTC](https://www.ruby-forum.com/t/help-writing-a-cron-job-to-get-flickr-photos/84913/1 "2007-02-08T17:10:14Z")

</div>

I’m currently using net/http to get my flickr data and displaying it on  
my site. I have a method in application.rb that sets up my layout, and  
does this everytime the page loads.

However, it was suggested to me that I write a cron job to pull in  
flickr data and cache it to a file in my rails app every 30 minutes or  
so, then use that file to display my images. How can I do this?

I’ve never written a cron job, and I don’t really know how the process  
works. Can I basically just put the ruby code that gathers the images  
into a file, and execute that file every 30 minutes via the cron job?  
If so, what’s the recommended way to handle the processing to get the  
images to appear on my site?

I was directed to this: [Configuring cron jobs with DreamHost | Setting up cron | Drupal Wiki guide on Drupal.org](http://drupal.org/node/31548)

But that’s only a small piece of the puzzle for me. Thanks for any  
help.

---

<div class="post-metadata">

**Author:** ![rph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c2a13f/32.png) [@rph](https://www.ruby-forum.com/u/rph)\
**Post date:** [February 8, 2007, 6:00pm UTC](https://www.ruby-forum.com/t/help-writing-a-cron-job-to-get-flickr-photos/84913/2 "2007-02-08T18:00:44Z")

</div>

On 2/8/07, rph [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> works. Can I basically just put the ruby code that gathers the images  
> into a file, and execute that file every 30 minutes via the cron job?  
> If so, what’s the recommended way to handle the processing to get the  
> images to appear on my site?
> 
> I was directed to this: [Configuring cron jobs with DreamHost | Setting up cron | Drupal Wiki guide on Drupal.org](http://drupal.org/node/31548)
> 
> But that’s only a small piece of the puzzle for me. Thanks for any  
> help.

You need to do two things which are separate cycles. The first is to  
write a script (in ruby or any language) to grab the flickr data.  
Once this script works from the command line you can instruct cron to  
execute the script at certain intervals.

To learn about cron, use google or man cron or man crontab.

Hope this helps.

–  
Zack C.  
[http://depixelate.com](http://depixelate.com)

---

<div class="post-metadata">

**Author:** ![rph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c2a13f/32.png) [@rph](https://www.ruby-forum.com/u/rph)\
**Post date:** [February 8, 2007, 9:00pm UTC](https://www.ruby-forum.com/t/help-writing-a-cron-job-to-get-flickr-photos/84913/3 "2007-02-08T21:00:26Z")

</div>

> You need to do two things which are separate cycles. The first is to  
> write a script (in ruby or any language) to grab the flickr data.  
> Once this script works from the command line you can instruct cron to  
> execute the script at certain intervals.
> 
> To learn about cron, use google or man cron or man crontab.
> 
> Hope this helps.
> 
> –  
> Zack C.  
> [http://depixelate.com](http://depixelate.com)

Ok, thanks. One more thing, is there a place to store the cron job? Or  
do you just execute it via command line and then it is always there?

---

<div class="post-metadata">

**Author:** ![rph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c2a13f/32.png) [@rph](https://www.ruby-forum.com/u/rph)\
**Post date:** [February 8, 2007, 9:13pm UTC](https://www.ruby-forum.com/t/help-writing-a-cron-job-to-get-flickr-photos/84913/4 "2007-02-08T21:13:06Z")

</div>

On 2/8/07, rph [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Hope this helps.
> > 
> > –  
> > Zack C.  
> > [http://depixelate.com](http://depixelate.com)
> 
> Ok, thanks. One more thing, is there a place to store the cron job? Or  
> do you just execute it via command line and then it is always there?

You add a line to a special file called crontab. This line specifies  
how often a job should be run. Run a man crontab to check out the  
format or use google.

–  
Zack C.  
[http://depixelate.com](http://depixelate.com)
