0

This is a long-shot and I'm writing because I have not idea where to start.

I want to write some code that can automatically and on regular basis grab the 5 dates from this website and put them into my iCal calender.

Where should I start and end to do this?

I'm pretty good in RoR and Javascript, but have absolutely no idea what technology I should use to accomplish this.

Hope you can shed some light on my question.

Thanks

SpeedBirdNine
  • 4,610
  • 11
  • 49
  • 67
Holger Sindbaek
  • 2,278
  • 6
  • 41
  • 68

3 Answers3

1

Assuming the HTML page is always going to keep the same basic structure, you could use something like nokogiri to locate the nodes containing the dates.

You can then use the Date.strptime or DateTime.strptime methods to convert the date from the particular format, into a Date or DateTime object, as required.

As for then adding the dates to your calendar, it's not something I have had to do, but you might want to check out How to interact with a CalDAV server from Ruby?

Community
  • 1
  • 1
SimonMayer
  • 4,719
  • 4
  • 33
  • 45
0

Use an XMLHttpRequest object in Javascript to download the page that you need and then use a regular expression to parse out the dates. It seems that the dates all have a fixed format:

<b>Mon Day Hr:Min UTC+4</b>

so it should be easy to write the regular expression for this. I don't know the exact Javascript Regex format but here's the .NET equivalent, it should be easy to tweak this to Javascript - hope this helps:

<b>(?<date>(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [0-9]{2} [0-9]{2}:[0-9]{2}) UTC[+-][0-9]+</b>

This finds all date fields in the page - once you have the date fields, each Regex match will have a sub-group named date that contains the actual date part.

If you go to this page: .NET Regex tester you can test the above expression to see how it returns the dates - just copy & paste your page's source with the dates. As I said, this is for .NET, not for Javascript but the differences are not terribly big.

xxbbcc
  • 16,930
  • 5
  • 50
  • 83
  • Great... Thanks. But then I wonder, will I have to go to a webpage each time I want this script to be run? Or can I somehow upload the script to itself and then let it call itself from time to time? – Holger Sindbaek Jan 28 '12 at 16:18
0

Use a Ruby script. The Mechanize gem can scrape the dates from the web page. Then the ri_cal gem can add them to your calendar. A pure JavaScript approach like xxbbcc suggested may be possible but it will almost certainly be more involved. If you're already familiar with Ruby, I'd recommend taking advantage of the "magic" and let these gems do the dirty work for you.

dgmdan
  • 405
  • 6
  • 14