Announcement

Collapse
No announcement yet.

Need help with Tide Script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Need help with Tide Script

    I would like to try to set up a script that will parse the tide chart I have attached. I keep the tide chart in my html directory. It is a little beyond my knowledge of parsing, so I need some help. What I would like to ultimately accomplish is to populate a device with the daily tide info. In order to do that, I would have to do the following:

    1. Have the script compare today's date with the date in the tide chart to select the correct date. The date is in a wierd format, but I don't know if that makes any difference.

    2. Have the script choose the second and third tide listings out of the three or four total listings for the day. Most days have 4 tide times, but some days only have 3. I only want to choose the 2nd and 3rd times no matter what.

    3. Have the script populate device T1 with today's tide info, including date and times of tides.

    If anyone feels like it, maybe you can show me what to do. I appreciate it. Thanks.
    Attached Files

    #2
    Beach,
    Would you rather populate a device or set up a web page to display this information?
    -Rupp
    sigpic

    Comment


      #3
      Here is a link that looks to have ended tides script

      Comment


        #4
        Beach,
        Drop this asp fiel into your HS HTML directory and name it any thing you want. Then call it jut like you would any other web page in your HTML directory and see if this is what your after:


        <pre class="ip-ubbcode-code-pre">
        &lt;%@ Language=VBScript %&gt;
        &lt;HTML&gt;
        &lt;HEAD&gt;
        &lt;/HEAD&gt;
        &lt;BODY&gt;
        &lt;%
        Response.Write "Tide Information Chart for : " & Date & "&lt;br&gt;"

        Set fso = Server.CreateObject("Scripting.FileSystemObject")

        path = server.MapPath("april_tides.txt")

        set file = fso.opentextfile(path, 1)

        ' Reorder the date information ...
        strTodaysDayName = weekdayname(weekday(date()))
        intMonth = month(date())
        if len(intMonth) &lt; 2 then intMonth = "0" & intMonth
        intDay = day(date())
        if len(intDay) &lt; 2 then intDay = "0" & intDay
        intYear = year(date())
        strCompleteDate = strTodaysDayName & " " & intYear & "-" & intMonth & "-" & intDay
        i = 0
        dim datagroup()
        do until file.AtEndOfStream
        strLineData = file.ReadLine
        if instr(1,strLineData,strCompleteDate) then
        do while strLineData &lt;&gt; ""
        redim preserve datagroup(i)
        strLineData = file.ReadLine
        datagroup(i) = strLineData
        i=i+1
        loop
        end if
        loop

        Response.Write datagroup(ubound(datagroup)-2) & "&lt;br&gt;"
        Response.Write datagroup(ubound(datagroup)-1) & "&lt;br&gt;"
        %&gt;

        &lt;/BODY&gt;
        &lt;/HTML&gt;
        </pre>
        -Rupp
        sigpic

        Comment


          #5
          Rupp,

          Thank you for taking time to help me. I got an error:

          Tide Information Chart for : 04/12/2004

          Script error: File not foundset file = fso.opentextfile(path, 1)
          ' Reorder the date information ...
          strTodaysDayName = weekdayname(weekday(date()))
          intMonth = month(date())
          if len(intMonth) &lt; 2 then intMonth = "0" & intMonth
          intDay = day(date())
          if len(intDay) &lt; 2 then intDay = "0" & intDay
          intYear = year(date())
          strCompleteDate = strTodaysDayName & " " & intYear & "-" & intMonth & "-" & intDay
          i = 0
          dim datagroup()
          do until file.AtEndOfStream
          strLineData = file.ReadLine
          if instr(1,strLineData,strCompleteDate) then
          do while strLineData &lt;&gt; ""
          redim preserve datagroup(i)
          strLineData = file.ReadLine
          datagroup(i) = strLineData
          i=i+1
          loop
          end if
          loop

          Response.Send datagroup(ubound(datagroup)-2) & ""
          Response.Send datagroup(ubound(datagroup)-1) & ""

          Comment


            #6
            Beach,
            The file april_tides.txt needs to be in the same directory as the asp file.
            -Rupp
            sigpic

            Comment


              #7
              Rupp,
              They are both in the html folder.

              Comment


                #8
                Beach,
                You do realize this is an asp page that is displayed in a browser right? It needs to be named something like tides.asp and called like :

                http://ipaddress:88/tides.asp
                -Rupp
                sigpic

                Comment


                  #9
                  I know, Rupp. I am still getting that error.

                  Comment


                    #10
                    Beach,
                    I'm sorry. I was coding this in IIS and the stupid HS web server doesn't do server.mappath. Try this one instead:

                    <pre class="ip-ubbcode-code-pre">
                    &lt;%@ Language=VBScript %&gt;
                    &lt;HTML&gt;
                    &lt;HEAD&gt;
                    &lt;/HEAD&gt;
                    &lt;BODY&gt;
                    &lt;%

                    Response.Write "Tide Information Chart for : " & Date & "&lt;br&gt;"

                    Set fso = Server.CreateObject("Scripting.FileSystemObject")

                    path = ("c:/program files/homeseer/html/april_tides.txt")

                    set file = fso.opentextfile(path, 1, True)

                    ' Reorder the date information ...
                    strTodaysDayName = weekdayname(weekday(date()))
                    intMonth = month(date())
                    if len(intMonth) &lt; 2 then intMonth = "0" & intMonth
                    intDay = day(date())
                    if len(intDay) &lt; 2 then intDay = "0" & intDay
                    intYear = year(date())
                    strCompleteDate = strTodaysDayName & " " & intYear & "-" & intMonth & "-" & intDay
                    i = 0
                    dim datagroup()
                    do until file.AtEndOfStream
                    strLineData = file.ReadLine
                    if instr(1,strLineData,strCompleteDate) then
                    do while strLineData &lt;&gt; ""
                    redim preserve datagroup(i)
                    strLineData = file.ReadLine
                    datagroup(i) = strLineData
                    i=i+1
                    loop
                    end if
                    loop

                    Response.Write datagroup(ubound(datagroup)-2) & "&lt;br&gt;"
                    Response.Write datagroup(ubound(datagroup)-1) & "&lt;br&gt;"
                    %&gt;

                    &lt;/BODY&gt;
                    &lt;/HTML&gt;

                    </pre>
                    -Rupp
                    sigpic

                    Comment


                      #11
                      Rupp,

                      Thanks a lot. I changed a few things, and turned your asp into a script, because I really want to just populate a device with the tide info. Here's what I did:


                      Set fso = CreateObject("Scripting.FileSystemObject")

                      path = ("c:/program files/homeseer/html/april_tides.txt")

                      set file = fso.opentextfile(path, 1, True)

                      ' Reorder the date information ...
                      strTodaysDayName = weekdayname(weekday(date()))
                      intMonth = month(date())
                      if len(intMonth) &lt; 2 then intMonth = "0" & intMonth
                      intDay = day(date())
                      if len(intDay) &lt; 2 then intDay = "0" & intDay
                      intYear = year(date())
                      strCompleteDate = strTodaysDayName & " " & intYear & "-" & intMonth & "-" & intDay
                      i = 0
                      dim datagroup()
                      do until file.AtEndOfStream
                      strLineData = file.ReadLine
                      if instr(1,strLineData,strCompleteDate) then
                      do while strLineData &lt;&gt; ""
                      redim preserve datagroup(i)
                      strLineData = file.ReadLine
                      datagroup(i) = strLineData
                      i=i+1
                      loop
                      end if
                      loop
                      if i=6 then
                      hs.SetDeviceString "t1",datagroup(ubound(datagroup)-2) & "&lt;br&gt;" & datagroup(ubound(datagroup)-1)
                      else
                      hs.SetDeviceString "t1",datagroup(ubound(datagroup)-3) & "&lt;br&gt;" & datagroup(ubound(datagroup)-2)
                      end if

                      It works, but I get a script error in line 0 every time. I don't know why? Does it matter?

                      Now what I would really want to do from here is create a vr scipt that will read today's high and low tides, and then have it determine what time it is now, and compare it to the high and low tide times, and then depending on the current time, have hs speak "It is currently 'xxx' tide. xxx would either be high, low or middle tide. Middle tide would be within an hour either way of high and low tide. So basically each tide including middle tide is approximately 2 hours. I would also like it to speak which tide is upcoming, either high or low (you don't need middle for this one). If you get time, maybe you can try it. Thanks again.

                      Comment


                        #12
                        Beach,
                        Do you have a sub main() at the top of the script? If not this can cause the error. As far as VR goes I haven't done any coding of that so hopefully you can find someone who has.
                        -Rupp
                        sigpic

                        Comment


                          #13
                          Rupp,

                          I'll try the sub main. I don't need vr, I just need to know how to program the times and comparisons. I'm just going to stick a vr in the start the script.

                          Comment

                          Working...
                          X