Public Holiday Greeting message

Version 1
    This document was generated from CDN thread

    Created by: Lisandro Quinteros on 16-04-2013 03:57:41 PM
    Hi again.. I am working on a script that play a different greeting message when the business is closed.
    Reading different posts and tcl programming guide I found that I think clock command cover my needs..
    Example.
     
    set day_of_week [clock format [clock seconds] -format %w]
        set hour [clock format [clock seconds] -format %H]
     
           if { $day_of_week == "0" || $day_of_week == "6" || $hour > 20 || $hour < 9 } {  # Out of hour
                   puts "business close" 
            } else {
                    puts "business open"                
            }
     
    But my problem now is how could  I set Public Holidays, because in my country every year the dates of a few public holidays changes so, Which is the easier way to do that? takes variable from http?
    How could I let an operator to set those dates and get them via param ?
     
    In case I define them on an array (inside tcl script) and need to compare them against a variable.. ( need to compare to make and If sentence )
    How could I compare a variable "today_date_is" vs. an array 
     
    set today_date_is [clock format [clock seconds] -format %D]
    holiday_date(1) 01/01/2013
    holiday_date(2) 02/05/2013
    holiday_date(3) 25/05/2013
    holiday_date(4) 25/12/2013
     
     if { $today_date_is == "any value of holiday_date array" } 
    Should I go thought all the array like  "for (i=0 to i=x  i++)" ??
    Any easier idea?
    Thanks in advance
     

    Subject: RE: Public Holiday Greeting message
    Replied by: Yaw-Ming Chen on 16-04-2013 04:23:24 PM
    Maybe you can put those holiday in a flat text file nd put in flash when load Tcl application load it cache
    When you get date of today you screen it form file that now is loaded in cache
    01012013 holiday_date1
    02052013 holiday_date2
    25052013 holiday_date3
    25122013 holiday_date4

    Subject: RE: Public Holiday Greeting message
    Replied by: Lisandro Quinteros on 17-04-2013 09:11:59 AM
    Thanks for you reply.. I will start researching because I have no idea how to load variables from a text file.
    It's seems to be a good choice… But I got another doubt now…
    Today I load in the text file 8 holiday dates..2 weeks later I have to add another date.. I would have to reload the tcl application to cache?
    And how it’s the syntaxes to make an IF statement to compare today_date_is vs. ALL dates from the text file… My idea is to make a generic If statement so when I add a new date to the text file it's not necessary to change the if statement…
     
    Thanks..

    Subject: RE: Public Holiday Greeting message
    Replied by: Yaw-Ming Chen on 17-04-2013 11:53:28 AM
    Lisandro Quinteros:
    Thanks for you reply.. I will start researching because I have no idea how to load variables from a text file. It's seems to be a good choice… But I got another doubt now… Today I load in the text file 8 holiday dates..2 weeks later I have to add another date.. I would have to reload the tcl application to cache? Just read the file when hetting ev_setup_indication then it should be fine And how it’s the syntaxes to make an IF statement to compare today_date_is vs. ALL dates from the text file… My idea is to make a generic If statement so when I add a new date to the text file it's not necessary to change the if statement…  How to compare the date string is really your choice. if possible I would use soemthing like "04172013" for April 17 2013. Thanks..
    This is an example of reading file. of cause this is NOT for your scenario. if [infotag get cfg_avpair_exists dial-file] {        set dial_file [string trim [infotag get cfg_avpair dial-file]]      } else {        set dial_file flash:/speed_dial.txt        puts -nonewline " -- ERROR: Mandatory parameter speed dial file does not exist added default flash --"          }    proc readDataFile { fname } {     global speedDialArray             if [catch {set fd [open $fname] } errmsg] {         error "Unable to open file: $fname for reading\n$errmsg"         return -1     }     set noDataRead 1     while {[gets $fd string] != -1} {         set key  [lindex $string 0]         set data  [lindex $string 1]         puts "File: $fname ::key: $key :ata: $data ::"         if { [regexp {^#} $key] } {             puts "Line is a comment"             continue         }         if { ![regexp {^[0-9]*$} $key] } {                                puts "Invalid Key: $key is given in file: $fname, ignoring this key option"             continue         }         if { [regexp {^[0-9]*$} $data] } {             puts "Speed Dial Phone number: $data is assigned to Key: $key"             set speedDialArray($key) $data             set noDataRead 0         }     }    ;#end of while     # Process any errors that occurred during the read     if ![eof $fd] {         error "Error occurred while reading 'somefile'"     }     close $fd     if { $noDataRead } {         log -s ERR "Tcl script : No data readed from Speed dial data file, please check the Content file, might be corrupted"     } } flat file format: 21 0123456789 24 1123456789

    Subject: RE: Public Holiday Greeting message
    Replied by: Paolo Bevilacqua on 17-04-2013 02:17:26 PM
    You can use my script "B-ACD/AA modifications" for this exact purpose. It can be acquired on http://ciscoscripts.com

    Subject: RE: Public Holiday Greeting message
    Replied by: Lisandro Quinteros on 07-05-2013 04:02:55 PM
    Yaw-Ming Chen thanks for your reply
    I got quite lost trying to read the file with dates so I will try to make it work when I have more time to deal with errors
     
    For now I have add all dates on and array like this..
    set a(0) "01012013"
      set a(1) "06072013"
      set a(2) "30122013"
      set a(3) "25122013"
    ....................
     
    and I have today date ex. $date=07052013
    I just need to compare $dato to a(X) array
     
    The working way is just :
    if { $date == "01012013" || $date == "06072013" || $date == "30122013" || $date == "25122013" }
     
    But I would like it more generic like...
     
    $todayisholiday==0
    for a=0 to a =4 a++
    if { $date=$a(X) } {
    $todayisholiday==1
    }
    end if
    end for
     
    How do i write this for sentence in the tcl script ...
    Or how can I just found $date on a(X) array ?
     
    Thanks again...
     

    Subject: RE: Public Holiday Greeting message
    Replied by: Lisandro Quinteros on 07-05-2013 04:04:58 PM
    variable mistake on sentence
    $todayisholiday==0
    for x=0 to x =4 x++
    if { $date=$a(X) } {
    $todayisholiday==1
    }
    end if
    end for

    Subject: RE: Public Holiday Greeting message
    Replied by: Lisandro Quinteros on 08-05-2013 11:59:04 AM
    I make this.. I think it could work
    set a(0) "01012013"
      set a(1) "06072013"
      set a(2) "30122013"
      set a(3) "25122013"
     set holiday "0"
    foreach n [array names a] {
     
    if {  $date == $a($n) } {
            puts "\n Today is a Holiday Day" 
       set holiday "1"
            } 
    }