It is currently April 26th, 2024, 3:01 pm

Extracting data from a Google Calendar RSS feed

Tips and Tricks from the Rainmeter Community
plasticup
Posts: 8
Joined: October 7th, 2010, 12:48 pm

Extracting data from a Google Calendar RSS feed

Post by plasticup »

Building regular expressions to extract data from a feed is easy but time consuming. The skins that I have dissected just extracted the information that they needed, usually in a way that made modification difficult. So here is the inelegant but comprehensive way that I have pulled every bit of information out of a Google Calendar RSS feed. Hopefully it will save someone a bit of time. (Note, the only bug I have found is that if your calendar events do not have an "event description" the rss feed just doesn't include the "Event Description:" element. This breaks stuff. To fix it, just delete the five instances of ".*Event Description: (.*)</content>" from my code and adjust the StringIndices accordingly)

Code: Select all

Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=1800
Url=http://www.google.com/calendar/feeds/#gcal.URL#/basic?max-results=8&futureevents=true&singleevents=true&orderby=starttime&sortorder=a
RegExp="(?siU)<title type='html'>(.*)</title>.*When: (.*) (.*) (.*), (.*) (.*) to (.*)&.*Where: (.*)&.*Event Description: (.*)</content>.*<title type='html'>(.*)</title>.*When: (.*) (.*) (.*), (.*) (.*) to (.*)&.*Where: (.*)&.*Event Description: (.*)</content>.*<title type='html'>(.*)</title>.*When: (.*) (.*) (.*), (.*) (.*) to (.*)&.*Where: (.*)&.*Event Description: (.*)</content>.*<title type='html'>(.*)</title>.*When: (.*) (.*) (.*), (.*) (.*) to (.*)&.*Where: (.*)&.*Event Description: (.*)</content>.*<title type='html'>(.*)</title>.*When: (.*) (.*) (.*), (.*) (.*) to (.*)&.*Where: (.*)&.*Event Description: (.*)</content>"
StringIndex=21
The variable #gcal.URL# should be replaced per the instructions of the Gnometer skin from which I took it:

See the original instructions in context here, from which I have quoted below
1) Go to http://www.google.com/calendar/render and click on Settings -> Calendar Settings
2) Click on the Calendars tab:
3) Then, click on the calendar of your choice (usually username@gmail.com)
4) Now click on the XML icon next to “Private Address”:
5) You will see a URL:
http://www.google.com/calendar/feeds/username%40gmail.com/private-f1f3a1042s3d4324d24asdadac43fe2a0/basic
6) The part in red is the URL you should enter into the Gnometer config tool.
This code will extract the following information about the calendar's next 5 events. The number's on this list correspond to the StringIndex assigned to that value:

EVENT 1
1. title
2. day of week
3. month
4. day of month
5. year
6. start time
7. end time
8. Location
9. Description

EVENT 2
10. title
11. day of week
12. month
13. day of month
14. year
15. start time
16. end time
17. Location
18. Description

EVENT 3
19. title
20. day of week
21. month
22. day of month
23. year
24. start time
25. end time
26. Location
27. Description

EVENT 4
28. title
29. day of week
30. month
31. day of month
32. year
33. start time
34. end time
35. Location
36. Description

EVENT 5
37. title
38. day of week
39. month
40. day of month
41. year
42. start time
43. end time
44. Location
45. Description
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Extracting data from a Google Calendar RSS feed

Post by Kaelri »

I'm going to give this method a thorough shakedown. I have had a very unpleasant experience trying to parse Google Calendar's feed, mainly because of the issue you cited: if certain metadata isn't provided, the tag just doesn't exist. I've found this to happen not only with the event description tag, but the 'where' tag, and even the time for all-day events. I think some of these problems can be solved with perl's "look ahead" syntax - the only problem being that if they're not there, the string indices will be shifted out of phase.

Anyway, if your regexp proves to work, and work consistently, I'll owe you a real debt of gratitude. :)
plasticup
Posts: 8
Joined: October 7th, 2010, 12:48 pm

Re: Extracting data from a Google Calendar RSS feed

Post by plasticup »

Ah, if they format their metadata in that way then you'll need a far more complex script to account for any such absences. I can imagine a RexExp argument searching ahead and determining whether a given field has been omitted, but it is certainly beyond my capacity to write such a code. However, my code grabs every possible value - if your set of calendar entries don't contain a given value you can delete it from the code and adjust your StringIndex accordingly. But if your calendar sporadically includes values for some events and not others (e.g. some locations, some descriptions, but is not consistent) then my script will return a jumbled pile of garbage. Sorry.
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Extracting data from a Google Calendar RSS feed

Post by Kaelri »

It's not your fault. It's Google's. ;) But yeah, I believe that if a skin of this type is to be made for general distribution, it needs to accommodate the full range of possible calendar entries, and that probably means removing all but the most reliable metadata entries. That said, this can be a great resource for individual users writing skins for personal use.
aidayong
Posts: 18
Joined: June 22nd, 2011, 7:59 am

Re: Extracting data from a Google Calendar RSS feed

Post by aidayong »

plasticup, thanks a lot. i have been searching high low finding gcal feed that is sorted for future event not when it was type. now i could used it with my vbs script.