Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/artyom-poptsov/guile-ics

iCalendar/vCard parser for GNU Guile.
https://github.com/artyom-poptsov/guile-ics

guile icalendar lisp parser rfc-5545 scheme

Last synced: 27 days ago
JSON representation

iCalendar/vCard parser for GNU Guile.

Awesome Lists containing this project

README

        

[[./doc/guile-ics.png]]
* Guile-ICS

[[https://github.com/artyom-poptsov/guile-ics][https://github.com/artyom-poptsov/guile-ics/workflows/GNU%20Guile%202.2/badge.svg]] [[https://github.com/artyom-poptsov/guile-ics][https://github.com/artyom-poptsov/guile-ics/workflows/GNU%20Guile%203.0/badge.svg]]

Guile-ICS is an iCalendar ([[https://tools.ietf.org/html/rfc5545][RFC 5545]]) and vCard ([[https://datatracker.ietf.org/doc/html/rfc6350][RFC 6350]]) parser for GNU Guile.

** License
Guile-ICS is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version. Please see =COPYING= file for the terms of GNU General
Public License.

The logo (=guile-ics.svg= and rasterised versions) is distributed
under terms of [[https://creativecommons.org/licenses/by-sa/4.0/][Creative Commons Attribution-ShareAlike 4.0
International]] license.

** Requirements
- [[https://www.gnu.org/software/guile/][GNU Guile]], version 2.0.12 or later
- [[https://github.com/artyom-poptsov/guile-smc][Guile-SMC]], version 0.6.0 or later
- [[https://github.com/artyom-poptsov/guile-dsv][Guile-DSV]], version 0.5.1 or later -- only required for the DSV converters;
the rest of Guile-ICS will work without this library.

*** Build-time dependencies
- GNU Guile development files (something with =dev= suffix, e.g.
=guile-3.0-dev= on Ubuntu GNU/Linux)
- texinfo
- make
- automake
- autoconf
- help2man

** Installation
*** GNU Guix
#+BEGIN_EXAMPLE shell
$ guix install guile-ics
#+END_EXAMPLE

To install the latest (unstable) version directly from the repository, run:
#+BEGIN_EXAMPLE shell
$ guix build -f ./guix.scm
$ guix package -f ./guix.scm
#+END_EXAMPLE

*** Manual
#+BEGIN_EXAMPLE shell
$ git clone https://github.com/artyom-poptsov/guile-ics.git
$ cd guile-ics
$ autoreconf -vif
$ ./configure
$ make -j$(nproc)
$ sudo make install
#+END_EXAMPLE

** Usage
*** Reading and printing iCalendar data
Let's suppose you have a file named =example.ics= with the
following content:
#+BEGIN_EXAMPLE
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:[email protected]
DTSTAMP:19970610T172345Z
DTSTART:19970714T170000Z
DTEND:19970715T040000Z
SUMMARY:Bastille Day Party
END:VEVENT
END:VCALENDAR
#+END_EXAMPLE

The following example shows how to parse the file:
#+BEGIN_EXAMPLE scheme
(use-modules (ics))

(let* ((port (open-input-file "example.ics"))
(ics-object (car (ics->scm port))))
(ics-pretty-print ics-object #:show-types? #t))
#+END_EXAMPLE

The code produces the following output:
#+BEGIN_EXAMPLE
BEGIN: VCALENDAR
PRODID (TEXT): -//hacksw/handcal//NONSGML v1.0//EN
VERSION (TEXT): 2.0
BEGIN: VEVENT
SUMMARY (TEXT): Bastille Day Party
DTEND (DATE-TIME): 19970715T040000Z
DTSTART (DATE-TIME): 19970714T170000Z
DTSTAMP (DATE-TIME): 19970610T172345Z
UID (TEXT): [email protected]
END: VEVENT
END: VCALENDAR
#+END_EXAMPLE

*** Describing iCalendar/vCard data
Now let's take a look on the =ics-object= structure more closely:
#+BEGIN_EXAMPLE scheme
(use-modules (ics))

(let* ((port (open-input-file "example.ics"))
(ics-object (car (ics->scm port))))
(ics-describe ics-object))
#+END_EXAMPLE

After we run the code we will see the following:
#+BEGIN_EXAMPLE
;;; VCALENDAR
;;; PRODID (TEXT: Text type: RFC5545, 3.3.11)
;;; -//hacksw/handcal//NONSGML v1.0//EN
;;; VERSION (TEXT: Text type: RFC5545, 3.3.11)
;;; 2.0
;;; VEVENT
;;; UID (TEXT: Text type: RFC5545, 3.3.11)
;;; [email protected]
;;; DTSTAMP (DATE-TIME: Date-Time type: RFC5545, 3.3.5)
;;; 19970610T172345Z
;;; DTSTART (DATE-TIME: Date-Time type: RFC5545, 3.3.5)
;;; 19970714T170000Z
;;; DTEND (DATE-TIME: Date-Time type: RFC5545, 3.3.5)
;;; 19970715T040000Z
;;; SUMMARY (TEXT: Text type: RFC5545, 3.3.11)
;;; Bastille Day Party
#+END_EXAMPLE

As can be seen from the example, the == with name =VCALENDAR=
has two properties of type =TEXT= (=PRODID=, and =VERSION=) and has one an
only =VEVENT= component. The =ics-describe= method may be handy in REPL mode
to get information about iCalendar objects. Now let's get the value of
=SUMMARY= property that belongs to the =VEVENT= component:
#+BEGIN_EXAMPLE scheme
(use-modules (ics)
(ics type object)
(ics type property))

(let* ((port (open-input-file "example.ics"))
(ics-object (car (ics->scm port)))
(vevent (car (ics-object-components ics-object))))
(display
(ics-property-value (ics-object-property-ref vevent "SUMMARY")))
(newline))

#+END_EXAMPLE

When run, the example prints the following:
#+BEGIN_EXAMPLE
Bastille Day Party
#+END_EXAMPLE

For more usage examples, see =examples= directory.
* =ics= tool
#+BEGIN_EXAMPLE
Usage ics [command] [options]

The default behaviour of the program is to read iCalendar/vCard stream from
stdin and handle it according to the specified options.

Commands:
print Print the input iCalendar data in various formats.
This is the default action if no command is provided.
describe Describe the input iCalendar data in the human-readable
form.
convert Convert data to the vCard/iCalendar format.
help Print this help message.

Options:
--help, -h Print this message and exit.
--version Print Guile-ICS version.

For each command there's '--help' option (or '-h' for short) that prints a help
message for the given command.
#+END_EXAMPLE

** =print=
This command allows to print iCalendar/vCard data in various formats:
#+BEGIN_EXAMPLE
$ ics print tests/example.ics
BEGIN: VCALENDAR
PRODID (TEXT): -//hacksw/handcal//NONSGML v1.0//EN
VERSION (TEXT): 2.0
BEGIN: VEVENT
UID (TEXT): [email protected]
DTSTAMP (DATE-TIME): 19970610T172345
DTSTART (DATE-TIME): 19970714T170000
DTEND (DATE-TIME): 19970715T040000
SUMMARY (TEXT): Bastille Day Party
END: VEVENT
END: VCALENDAR
#+END_EXAMPLE

** =describe=
#+BEGIN_EXAMPLE
$ ics describe tests/example.ics
;;; VCALENDAR
;;; PRODID (TEXT: Text type: RFC5545, 3.3.11)
;;; -//hacksw/handcal//NONSGML v1.0//EN
;;; VERSION (TEXT: Text type: RFC5545, 3.3.11)
;;; 2.0
;;; VEVENT
;;; UID (TEXT: Text type: RFC5545, 3.3.11)
;;; [email protected]
;;; DTSTAMP (DATE-TIME: Date-Time type: RFC5545, 3.3.5)
;;; 19970610T172345Z
;;; DTSTART (DATE-TIME: Date-Time type: RFC5545, 3.3.5)
;;; 19970714T170000Z
;;; DTEND (DATE-TIME: Date-Time type: RFC5545, 3.3.5)
;;; 19970715T040000Z
;;; SUMMARY (TEXT: Text type: RFC5545, 3.3.11)
;;; Bastille Day Party
#+END_EXAMPLE

** =convert=
This command allows to convert input data into iCalendar/vCard format.

Let's say we have the following data:
#+BEGIN_EXAMPLE
ORG,TITLE,FN,EMAIL
Example Organisation,Programmer,Eva Luator,[email protected]
Example Organisation,Programmer,Random J. Hacker,[email protected]
#+END_EXAMPLE

Then we can convert it to vCard as follows:
#+BEGIN_EXAMPLE
$ ics convert test.csv
BEGIN:VCARD
EMAIL:[email protected]
FN:Eva Luator
TITLE:Programmer
ORG:Example Organisation
END:VCARD

BEGIN:VCARD
EMAIL:[email protected]
FN:Random J. Hacker
TITLE:Programmer
ORG:Example Organisation
END:VCARD

#+END_EXAMPLE