iCalendar module?

Discussion in 'Perl Misc' started by hymie!, May 23, 2013.

  1. hymie!

    hymie! Guest

    Greetings.

    I found this ruby script
    cals = Icalendar.parse($<)
    cals.each do |cal|
    cal.events.each do |event|
    puts "Organizer: #{event.organizer}"
    puts "Event: #{event.summary}"
    puts "Starts: #{event.dtstart.myformat} local time"
    puts "Ends: #{event.dtend.myformat}"
    puts "Location: #{event.location}"
    puts "Contact: #{event.contacts}"
    puts "Description:\n#{event.description}"
    puts ""
    end
    end

    and I was hoping to write something similar in perl.

    The question is, can somebody recommend to me a module that I can use
    to read iCal files? All of the modules that I see appear to handle
    creating iCal files, but not reading them and outputting something
    human-readable. Although it's likely that I missed it.

    --hymie! http://lactose.homelinux.net/~hymie
    -------------------------------------------------------------------------------
    hymie!, May 23, 2013
    #1
    1. Advertising

  2. On 2013-05-23 19:50, hymie! <> wrote:
    > I found this ruby script
    > cals = Icalendar.parse($<)
    > cals.each do |cal|
    > cal.events.each do |event|
    > puts "Organizer: #{event.organizer}"
    > puts "Event: #{event.summary}"
    > puts "Starts: #{event.dtstart.myformat} local time"

    [...]
    >
    > and I was hoping to write something similar in perl.
    >
    > The question is, can somebody recommend to me a module that I can use
    > to read iCal files? All of the modules that I see appear to handle
    > creating iCal files, but not reading them and outputting something
    > human-readable. Although it's likely that I missed it.


    I have used Text::vFile::asData to convert iCal MIME parts to something
    I can read. It handles all the v-type formats (vCalendar, vCard, ...),
    but that flexibility makes it a bit cumbersome to use. Here's a snippet
    from my script (whole script available on request if anyone wants it):

    ....
    my $data = Text::vFile::asData->new->parse(\*STDIN);

    my $vcalendar = $data->{objects}[0];
    die "unexpected type $vcalendar->{type}" unless $vcalendar->{type} eq 'VCALENDAR';

    my $vevent;
    for (@{ $vcalendar->{objects} }) {
    if ($_->{type} eq 'VEVENT') {
    $vevent = $_;
    last; # there can be only one (or so we hope)
    }
    }
    die "no VEVENT found" unless $vevent;

    print "Summary : $vevent->{properties}{SUMMARY}[0]{value}\n";
    print "\n";
    print "Begin : ", fmttime($vevent->{properties}{DTSTART}[0]{value}), "\n";
    print "End : ", fmttime($vevent->{properties}{DTEND}[0]{value}), "\n";
    print "\n";
    ....

    hp


    --
    _ | Peter J. Holzer | Fluch der elektronischen Textverarbeitung:
    |_|_) | Sysadmin WSR | Man feilt solange an seinen Text um, bis
    | | | | die Satzbestandteile des Satzes nicht mehr
    __/ | http://www.hjp.at/ | zusammenpaƟt. -- Ralph Babel
    Peter J. Holzer, May 24, 2013
    #2
    1. Advertising

  3. hymie!

    hymie! Guest

    In our last episode, the evil Dr. Lacto had captured our hero,
    "Peter J. Holzer" <>, who said:
    >On 2013-05-23 19:50, hymie! <> wrote:
    >> I found this ruby script
    >> cals = Icalendar.parse($<)
    >> cals.each do |cal|
    >> cal.events.each do |event|
    >> puts "Organizer: #{event.organizer}"
    >> puts "Event: #{event.summary}"
    >> puts "Starts: #{event.dtstart.myformat} local time"

    >[...]
    >>
    >> and I was hoping to write something similar in perl.
    >>

    >I have used Text::vFile::asData to convert iCal MIME parts to something
    >I can read. It handles all the v-type formats (vCalendar, vCard, ...),
    >
    >...
    >my $data = Text::vFile::asData->new->parse(\*STDIN);
    >
    >my $vcalendar = $data->{objects}[0];
    >die "unexpected type $vcalendar->{type}" unless $vcalendar->{type} eq
    >'VCALENDAR';
    >
    >my $vevent;
    >for (@{ $vcalendar->{objects} }) {
    > if ($_->{type} eq 'VEVENT') {
    > $vevent = $_;
    > last; # there can be only one (or so we hope)
    > }
    >}
    >die "no VEVENT found" unless $vevent;
    >
    >print "Summary : $vevent->{properties}{SUMMARY}[0]{value}\n";
    >print "\n";
    >print "Begin : ", fmttime($vevent->{properties}{DTSTART}[0]{value}), "\n";
    >print "End : ", fmttime($vevent->{properties}{DTEND}[0]{value}), "\n";
    >print "\n";


    Perfect! Thank you very much.

    --hymie! http://lactose.homelinux.net/~hymie
    -------------------------------------------------------------------------------
    hymie!, May 28, 2013
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Johannes

    iCalendar problem

    Johannes, Feb 10, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    429
    Johannes
    Feb 10, 2006
  2. Stefan Neuhaus

    API for RFC 2445 iCalendar

    Stefan Neuhaus, Dec 19, 2003, in forum: Java
    Replies:
    0
    Views:
    476
    Stefan Neuhaus
    Dec 19, 2003
  3. Max M

    [ANN] iCalendar package 0.9

    Max M, Jan 17, 2005, in forum: Python
    Replies:
    2
    Views:
    314
    Max M
    Jan 18, 2005
  4. Replies:
    0
    Views:
    253
  5. Replies:
    1
    Views:
    326
    Chris Rebert
    Mar 13, 2009
Loading...

Share This Page