Announcement

Collapse
No announcement yet.

Google Calender script from HS2 to HS3

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

    #91
    No worries...I think the library is a bit involved but designed for more complex applications than being used here in just browsing. There may be simpler libraries out there even - it was just the first one I found!

    Comment


      #92
      Thanks Adam:

      Works quite nicely; really appreciate you sharing the code.
      Don

      Comment


        #93
        Adam:

        I'm trying to convert the UTC time to local using the toLocalTime function, and having no luck. Could you tweak your example to show how to do this? Also, how do I pull the event start time out of your example?

        Thanks
        Last edited by donstephens; January 15, 2015, 01:17 PM.
        Don

        Comment


          #94
          Don

          You may need to spell it out to me, the UTC time you are talking about - is that a query time you are trying to specify to get a list of events for between certain times? I remember the time formatting was slightly odd I have to be honest but I am not sure what exactly you mean by it. I get the start time by gCalEntry.Period.StartTime.

          Comment


            #95
            Figured it out. Found some examples and reverse engineered.

            Thanks
            Don

            Comment


              #96
              MrHappy,

              I think the biggest issue in your script is this line

              Dim SpeechString As String = Nothing

              When there are no calendar entries, you call hs.speak with a nill pointer.

              I would change all your occurrences to

              Dim SpeechString As String = ""

              .... if SpeechString <> "" ......

              and at the end of your script, check whether the SpeechString <> "" before calling HS.speak

              Here is the updated script I ran and note it is routing the output to Sonos so remove or update the $SONOS$TTS$ to reflect your settings.

              Code:
              Imports DDay.iCal
              Imports System.Collections.Generic
              Imports System.Text
              
              Dim CalURL As String = "https://www.google.com/calendar/ical/xxxxxx%40gmail.com/private-yyyyyyyyyyyyyyyyyy/basic.ics"
              
              'http://ehc.ac/projects/dday-ical/ is a .net library for iCalendar file formats
              'this links to Google, then downloads the following days entries
              'all I want to do is list tomorrows work schedule
              'put some values in some global variables, a boolean -
              'http://www.codeproject.com/Articles/17980/Adding-iCalendar-Support-to-Your-Program-Part
              
              Sub Main(ByVal Parm As Object)
              
                  Try
                      Log("GoogleCalendar Script Starting")
              
                      Dim gCalendar As IICalendarCollection
                      Dim gCalOccList As IList(Of DDay.iCal.Occurrence)
                      Dim gCalEnt As DDay.iCal.IRecurringComponent
              
                      Dim StartDate As DateTime = DateTime.Today.AddDays(1) 'this will be tomorrow
                      Dim FinishDate As DateTime = DateTime.Today.AddDays(2) 'this will be the end of tomorrow
              
                      gCalendar = iCalendar.LoadFromUri(New Uri(CalURL))
                      Try
                          gCalOccList = gCalendar.GetOccurrences(StartDate, FinishDate)
                      Catch ex As Exception
                          Log("Exception getting gCalOccList: " & ex.Message.ToString)
                          Exit Sub
                      End Try
              
                      Dim SpeechString As String = ""
              
                      If gCalOccList IsNot Nothing Then
                          Try
                              For Each gCalEntry As Occurrence In gCalOccList 'do I need to worry about stuff that is left in the calendar by error
                                  Log("--- New Work Entry ---")
                                  Log("Start Time: " & gCalEntry.Period.StartTime.ToString("dd/MM/yyyy HH:mm") & " End Time: " & gCalEntry.Period.EndTime.ToString("dd/MM/yyyy HH:mm"))
                                  gCalEnt = gCalEntry.Source
                                  If gCalEnt IsNot Nothing Then
                                      If SpeechString = "" Then
                                          SpeechString = "Tomorrow at " & gCalEntry.Period.StartTime.ToString("HH:mm").Replace("UTC", Nothing) & "you are " & gCalEnt.Summary & " until " & gCalEntry.Period.EndTime.ToString("HH:mm").Replace("UTC", Nothing)
                                      Else : SpeechString = SpeechString & " after that you have " & gCalEnt.Summary & " at " & gCalEntry.Period.StartTime.ToString("HH:mm").Replace("UTC", Nothing) & " until " & gCalEntry.Period.EndTime.ToString("HH:mm").Replace("UTC", Nothing)
                                      End If
                                  End If
                                  Log("--- End Of Work Entry ---")
                              Next
                          Catch ex As Exception
                              Log("Exception in gCalOccList: " & ex.Message.ToString)
                          End Try
                      End If
              
                      speechstring = speechstring.tolower
              
                      Log("Speech String: " & speechstring)
                      If speechstring <> "" Then hs.speak(speechstring, True, "$SONOS$TTS$")
                      Log("End Of GoogleCalendar Script")
              
                  Catch ex As Exception
                      Log("Exception: " & ex.ToString)
                  End Try
              
              End Sub
              
              Sub Log(ByVal ParStr As String)
                  hs.writelog("GoogleCalendar Script", ParStr)
              End Sub

              Comment


                #97
                Fair enough I could see where that would be an issue on an empty calendar and thanks for posting the fix.

                That does not appear the issue with the reason I can get HS to crash in my setup though unfortunately as I can crash it on speech from the control panel not the script (that is how I got it to crash in the thread in your forum). I am not blaming the Sonos plugin as it is a HS crash rather than a plugin crash, I imagine I have done something at some time which is causing an upset inside HS - quite what I do not know but I am going to wait to see if and when I get HS on some other hardware that has not quite been as messed with as mine then I will re-test it.

                Comment


                  #98
                  Does this require the calendar to be shared as public for the script to work? I'm getting the following error. What needs to be modified besides the CalURL to work in my environment?


                  Jan-27 11:13:41 PM GoogleCalendar Script Exception getting gCalOccList: Object reference not set to an instance of an object.

                  Comment


                    #99
                    No there is no requirement for the calendar to be public for this to work, nothing apart from CalURL needs to be modified as long as you have declared the DLL files although I would expect a different error if there was an error there. That is not an error I have seen before, to help could you answer;

                    1) If you paste the Calendar URL you have put into CalURL into a browser does the .ics file download, if so can you open it in Notepad and is there data in there? The file should start "BEGIN:VCALENDAR" or something.

                    2) Are you using the exact same script I put in post #52 or have you modified it at all?

                    3) What are the times and dates you are querying the calendar for? Are they round the correct way?

                    Comment


                      Originally posted by mrhappy View Post
                      No there is no requirement for the calendar to be public for this to work, nothing apart from CalURL needs to be modified as long as you have declared the DLL files although I would expect a different error if there was an error there. That is not an error I have seen before, to help could you answer;

                      1) If you paste the Calendar URL you have put into CalURL into a browser does the .ics file download, if so can you open it in Notepad and is there data in there? The file should start "BEGIN:VCALENDAR" or something.

                      2) Are you using the exact same script I put in post #52 or have you modified it at all?

                      3) What are the times and dates you are querying the calendar for? Are they round the correct way?
                      I see what's different here. My Google Apps account have 'public' in the URL and when I paste it in a browser, instead of downloading the .ics file, I get 'Feed Processing Error'. When I paste my Gmail calendar url in the browser, it prompts to save the file.

                      https://www.google.com/calendar/ical...blic/basic.ics

                      I tried both your script and the most recent one with the speak option. Both gave the 'Object reference..' message. I also have not modified the dates yet. Wanted to see the results first.

                      So I guess this may only work with Gmail accounts and not Google Apps account?

                      Comment


                        Originally posted by Sireone View Post
                        I see what's different here. My Google Apps account have 'public' in the URL and when I paste it in a browser, instead of downloading the .ics file, I get 'Feed Processing Error'. When I paste my Gmail calendar url in the browser, it prompts to save the file.

                        https://www.google.com/calendar/ical...blic/basic.ics

                        I tried both your script and the most recent one with the speak option. Both gave the 'Object reference..' message. I also have not modified the dates yet. Wanted to see the results first.

                        So I guess this may only work with Gmail accounts and not Google Apps account?
                        I get the URL from the calendar settings page, I did not know there was another source to be honest, if you can point me to another iCal source I can check with it.

                        As long as the file is downloading and you are using this URL in the script then the script should work without an error, can you confirm you are using the URL from the same place I am on the screenshot? If so are there events tomorrow that the script should be picking up?
                        Last edited by mrhappy; January 31, 2015, 05:28 PM.

                        Comment


                          Originally posted by mrhappy View Post
                          I get the URL from the calendar settings page, I did not know there was another source to be honest, if you can point me to another iCal source I can check with it.

                          As long as the file is downloading and you are using this URL in the script then the script should work without an error, can you confirm you are using the URL from the same place I am on the screenshot? If so are there events tomorrow that the script should be picking up?
                          Yep..I looked at two Google Apps account and only see the Calender Address, not the 'Private..' address. ON my personal Gmail calendar, I see both like your image.
                          Attached Files

                          Comment


                            OK I see what you mean by that now, I have just clicked on mine and get the same Feed Processing Error even if I make my calendar public (which according to Google should enable that) when I click that button. As the .ics file does not even seem to be there this is undoubtedly why the script is failing.

                            Not sure I fully understand how these calendars are being generated, are they by some third party application? According to some Googling if this is the case then it is that application that allows control over whether the calendar can have it's private address enabled. If you don't have control over it then unfortunately I think this script is a little stuck.

                            Comment


                              Having some difficulty connecting

                              Mr. Happy,

                              I too am trying to use this script.

                              I have read these threads and followed the instructions, but am getting a Error 403 Forbidden. I recognize that Google Calendar may have changed somewhat since these posts (some of the steps do not line up exactly). I have copied the URL from Google Calendar by going to the Calendar Details page and copying the XML link. I have tried both the Private Address and the Calendar Address links. I have tried with the calendar set for Public Access enabled and disabled. I am doing testing directly through a web browser, and I found that using the links with .../basic returns what seems to be good data. Using the link with .../full, however, returns the Error 403 Forbidden.

                              I have also done this via an event in HS3 where I am using your script and I have the proper user credentials in the script. I get the same result in the HS3 Log (although there it is error ...unexpected result: 404)

                              I'm sure I have simply missed a step somewhere that likely is related to my user credentials, but I just don't see it.

                              Any advice?

                              -John

                              Comment


                                Originally posted by JazzmanJohn View Post
                                Mr. Happy,

                                I too am trying to use this script.

                                I have read these threads and followed the instructions, but am getting a Error 403 Forbidden. I recognize that Google Calendar may have changed somewhat since these posts (some of the steps do not line up exactly). I have copied the URL from Google Calendar by going to the Calendar Details page and copying the XML link. I have tried both the Private Address and the Calendar Address links. I have tried with the calendar set for Public Access enabled and disabled. I am doing testing directly through a web browser, and I found that using the links with .../basic returns what seems to be good data. Using the link with .../full, however, returns the Error 403 Forbidden.

                                I have also done this via an event in HS3 where I am using your script and I have the proper user credentials in the script. I get the same result in the HS3 Log (although there it is error ...unexpected result: 404)

                                I'm sure I have simply missed a step somewhere that likely is related to my user credentials, but I just don't see it.

                                Any advice?

                                -John
                                You should only need the /basic which as it is returning good data should be fine. Just clarify are you using the method in post #52 rather than anything else?

                                The old method used an API method that now no longer works so I had to move to the method in post #52, that does not need login credentials and instead just needs a link to point to the iCal file.

                                Comment

                                Working...
                                X