Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Outputting Info To A Web Page Depending On Time and day of week

Posted on 1999-07-06
17
Medium Priority
?
184 Views
Last Modified: 2010-03-04
I would like to know how to print specified data to an html file depending on the time. I am using it for a radio station that would print who is on the air at that particular time. IE:

If the time is between 5:30 - 10AM, then it would print

Currently On The Air
Joe Smith

Or if its between 10AM - 2PM, it would print

Currently On The Air
Joe Blow

I am a total newbie to perl, so I would appreciate an example script if possible. I will raise the points if needed.

Thanks in advance
0
Comment
Question by:phreakin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 7
17 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1213892
($hour,$minute)=(localtime)[2,1];
if( $hour*60+minute >= 5*60+30 && $hour*60+minute < 10*60+0 ){
        print "Joe Smith\n";
}elsif( $hour*60+minute >= 10*60+0 && $hour*60+minute < (12+2)*60+0 ){
        print "Joe Blow\n";
}
0
 
LVL 84

Expert Comment

by:ozo
ID: 1213893
if( $hour*60+$minute >= 5*60+30 && $hour*60+$minute < 10*60+0 ){
        print "Joe Smith\n";
}elsif( $hour*60+$minute >= 10*60+0 && $hour*60+$minute < (12+2)*60+0 ){
        print "Joe Blow\n";
}
0
 

Author Comment

by:phreakin
ID: 1213894
So do I just repeat that for as many times as I need for each person? ie, if I have five people I would use those lines 5 times. Sorry Ozo, I am illiterate to this. I will raise the points to 110 if you can give me a full sample script.

Thanks
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:phreakin
ID: 1213895
So do I just repeat that for as many times as I need for each person? ie, if I have five people I would use those lines 5 times. Sorry Ozo, I am illiterate to this. I will raise the points to 110 if you can give me a full sample script.

Thanks
0
 
LVL 84

Expert Comment

by:ozo
ID: 1213896
#!/usr/bin/perl
($hour,$minute)=(localtime)[2,1];
if( $hour*60+$minute >= 5*60+30 && $hour*60+$minute < 10*60+0 ){
        $name= "Joe Smith";
}elsif( $hour*60+$minute >= 10*60+0 && $hour*60+$minute < (12+2)*60+0 ){
        $name= "Joe Blow";
}
print <<END_HERE;
Content-Type: text/html

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML><HEAD><TITLE>Example</TITLE>
</HEAD><BODY>
Currently On The Air <br>
$name<br>
</BODY></HTML>
END_HERE
0
 

Author Comment

by:phreakin
ID: 1213897
So do I just repeat that for as many times as I need for each person? ie, if I have five people I would use those lines 5 times. Sorry Ozo, I am illiterate to this. I will raise the points to 110 if you can give me a full sample script.

Thanks
0
 

Author Comment

by:phreakin
ID: 1213898
It seems to not print anything for a name. The script works fine but it doesn't print the name. I am running perl 4 on BSDI 4.1 if that makes any difference.

This is the output

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML><HEAD><TITLE>Example</TITLE>
</HEAD><BODY>
Currently On The Air <br>
<br>
</BODY></HTML>
0
 

Author Comment

by:phreakin
ID: 1213899
Nevermind...lol
0
 
LVL 84

Expert Comment

by:ozo
ID: 1213900
What time is it?
0
 

Author Comment

by:phreakin
ID: 1213901
Nevermind...lol
0
 

Author Comment

by:phreakin
ID: 1213902
Apparently my server time is 8 hours behind. Ozo: If I send you a modified script can you take a look and see if it's right?
0
 
LVL 84

Expert Comment

by:ozo
ID: 1213903
It'a hard to see if it's right without a look...
0
 

Author Comment

by:phreakin
ID: 1213904
The script is as follows:

#!/usr/bin/perl

($hour,$minute)=(localtime)[2,1];
if( $hour*60+$minute >= 3*60+30 && $hour*60+$minute < 10*60+0 ){
        $name= "Mancow";

}elsif( $hour*60+$minute >= 10*60+0 && $hour*60+$minute < (12+2)*60+0 ){
        $name= "Byron Kennedy";

}elsif( $hour*60+$minute >= 14*60+0 && $hour*60+$minute < 19*60+0 ){
        $name= "Budman";

}elsif( $hour*60+$minute >= 19*60+0 && $hour*60+$minute < (12+12)*60+0 ){
        $name= "Joe Blow";
}
print <<END_HERE;
Content-Type: text/html

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML><HEAD><TITLE></TITLE>
</HEAD><BODY>
Currently On The Air <br>
$name<br>
</BODY></HTML>
END_HERE


The actual times I need it to do are as follows:
3:30AM - 10AM
10:00AM - 12Noon
12Noon - 3PM
3PM - 7PM
7PM - Midnight
Midnight - 3:30 AM

These would only be Monday through Fridat. I wouldn't be able to use it for weekends because the people change.
0
 
LVL 84

Expert Comment

by:ozo
ID: 1213905
$hhmm = $hour*60+$minute;
if( $hhmm >= 3*60+30 && $hhmm < 10*60+0 ){
        $name= "3:30AM - 10AM";
}elsif( $hhmm >= 10*60+0 && $hhmm < 12*60+0 ){
        $name= "10:00AM - 12Noon";
}elsif( $hhmm >= 12*60+0 && $hhmm < (12+3)*60+0 ){
        $name= "12Noon - 3PM";
}elsif( $hhmm >= (12+3)*60+0 && $hhmm < (12+7)*60+0 ){
        $name= "3PM - 7PM";
}elsif( $hhmm >= (12+7)*60+0 ){
        $name= "7PM - Midnight";
}elsif( $hhmm < 3*60+30 ){
        $name= "Midnight - 3:30 AM";
}
#you can also get the day of the week with
($hour,$minute,$weekday)=(localtime)[2,1,6];
0
 

Author Comment

by:phreakin
ID: 1213906
Ozo:

Submit an answer so I can give you the points. I appreciate the help. The script works perfect. :)
0
 

Author Comment

by:phreakin
ID: 1213907
Ozo:

Submit an answer so I can give you the points. I appreciate the help. The script works perfect. :)
0
 
LVL 84

Accepted Solution

by:
ozo earned 200 total points
ID: 1213908
Ok. Can you handle the day of week part by yourself now?
I wasn't sure how you'd want that part of the schedule changed.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question