Looking for cgi script to change content based on time of day

Discussion in 'Perl Misc' started by danny, Aug 22, 2006.

  1. danny

    danny Guest

    I'm doing a website for a radio station. They want to display an image
    of the dj that is presenting at a certain time on the home page. In
    other words they want a script that displays a certain image depending
    on the day of the week and the time of day. Their weekly schedule
    doesn't change. Any help would be great.

    Thank you,
    Danny.
    danny, Aug 22, 2006
    #1
    1. Advertising

  2. danny

    Matt Garrish Guest

    danny wrote:

    > I'm doing a website for a radio station. They want to display an image
    > of the dj that is presenting at a certain time on the home page. In
    > other words they want a script that displays a certain image depending
    > on the day of the week and the time of day. Their weekly schedule
    > doesn't change. Any help would be great.
    >


    This isn't the place to ask for pre-written code. There's jobs.perl.org
    if you're in over your head and need a contractor, otherwise if you''d
    explain why calling localtime and displaying an image based on the
    output is causing you problems, and show what you've tried so far,
    someone might be willing to help you with it.

    Matt
    Matt Garrish, Aug 22, 2006
    #2
    1. Advertising

  3. danny

    Guest

    danny <> wrote:
    > I'm doing a website for a radio station. They want to display an image
    > of the dj that is presenting at a certain time on the home page. In
    > other words they want a script that displays a certain image depending
    > on the day of the week and the time of day. Their weekly schedule
    > doesn't change. Any help would be great.


    What are you willing to pay for such a script?

    This is not a place to expect people to do your work for free.
    If you cannot even make an effort yourself, you are in the wrong job.

    Axel
    , Aug 23, 2006
    #3
  4. danny

    Guest

    danny wrote:
    > they want a script that displays a certain image depending
    > on the day of the week and the time of day.


    The "trick" is to decide how you will tell your program which DJ is
    working which day/hour. There are LOTS of ways you can do that.

    If your schedule is not very granular (ie, everything can be defined in
    whole hours) you can incorporate something like this, which sacrifices
    a small amount of efficiency (but over a very tiny data structure) for
    something that's easy to define and easy to override for oddball
    schedule changes. This creates a matrix (7 days x 24 hourly time
    slots):

    #!/usr/bin/perl
    use strict; use warnings;
    use CGI qw{ img };

    my %dj_img;

    foreach my $day(1..5) { #weekday schedule
    map {$dj_img{$day}{$_} = 'fatguy.jpg' } ( 0.. 5); #Fred- m'night-6
    map {$dj_img{$day}{$_} = 'barney.jpg' } ( 6.. 8); #Barney-morning
    map {$dj_img{$day}{$_} = 'wilma.jpg' } ( 9..15); #Wilma- midday
    map {$dj_img{$day}{$_} = 'betty.jpg' } (16..19); #Betty-afternoon
    map {$dj_img{$day}{$_} = 'redhead.jpg' } (20..23); #Pebbles- night
    }

    foreach my $day(0,6) { #weekend schedule
    map {$dj_img{$day}{$_} = 'bambam.jpg'} (0..9); #BamBam-w'end am
    #etc.
    }

    # Now somewhere in our CGI script, we print the image tags:
    print img( { -src => $dj_img{(localtime)[6]}{(localtime)[2]} });
    # DAY HOUR


    --
    David Filmer (http://DavidFilmer.com)
    , Aug 23, 2006
    #4
  5. danny <> wrote:

    > they want a script that displays a certain image depending
    > on the day of the week and the time of day.



    perldoc -f localtime


    > Any help would be great.



    You're welcome.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Aug 23, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy
    Replies:
    1
    Views:
    700
  2. Replies:
    2
    Views:
    274
  3. Rob Redmon

    Convert day of year to month, day

    Rob Redmon, Apr 4, 2008, in forum: Ruby
    Replies:
    7
    Views:
    297
    Alex Wayne
    Apr 4, 2008
  4. Stan Brown
    Replies:
    2
    Views:
    97
    Ted Zlatanov
    Jun 25, 2003
  5. kath
    Replies:
    4
    Views:
    565
    J. Gleixner
    Apr 9, 2007
Loading...

Share This Page