Next / Previous / Contents / TCC Help System / NM Tech homepage

Abstract

Describes an application that reads Unix ical .calendar files using the Python programming language. The application demonstrates Python's pyparsing recursive descent parsing module. All source code is included in lightweight literate form.

This publication is available in Web form and also as a PDF document. Please forward any comments to tcc-doc@nmt.edu.

Table of Contents

1. Context: Using pyparsing to salvage legacy scheduling information
2. Online files
3. The .calendar format
3.1. Glossary
3.2. Format of the Note entry
3.3. Format of the Appt command
3.4. The Dates command and its clauses
4. A grammar for .calendar
4.1. The goal symbol: filePattern
4.2. The header pattern
4.3. The entry pattern
4.4. The command pattern
4.5. The textCommand pattern
4.6. The dateCommand pattern
5. Interface to the parsecal module
5.1. Constants
5.2. IcalError: Our exception
5.3. class Ical: The entire file
5.4. class Note: One entry
5.5. class Repeater
5.6. class TimeRange
6. icalparse: The driver script
7. parsecal.py: Prologue
8. Imports
9. Constants
9.1. Command names
9.2. Clause names
9.3. Result field names
9.4. Repeat kind codes
9.5. HEADER_NAMES
9.6. SIMPLE_NAMES
9.7. MULTI_CLAUSE_NAMES
9.8. LIMIT_CLAUSE_NAMES
9.9. ENTRY_NAMES
10. Syntax productions
10.1. integer
10.2. bracketGroup
10.3. header
10.4. simpleCommand
10.5. countedText
10.6. textCommand
10.7. dmyDate
10.8. datesCommand
10.9. filePattern: The goal symbol
11. class IcalError
12. class Ical
12.1. Ical.genNotes(): Generate all entries
12.2. Ical.__init__()
13. class Note
13.1. Note.__cmp__()
13.2. Note.__init__()
13.3. Note.convert()
13.4. Note._findRepeat()
13.5. Note._repeatKind(): What kind of repeat is this?
13.6. Note._findTimeRange(): Bracket the appointment time
14. class Repeater
15. class TimeRange
16. icalparse: Driver script for the parsecal module
16.1. icalparse: Prologue
16.2. icalparse: Imports
16.3. icalparse: Constants
16.4. icalparse: main()
16.5. icalparse: show(): Display one entry
16.6. icalparse: fatal()
16.7. icalparse: Epilogue

1. Context: Using pyparsing to salvage legacy scheduling information

The ical application is a calendar manager from the Unix world that dates back well before the year 2000. The original was written in the Tcl/tk language by Sanjay Ghemawat; refer to the Wikipedia page for more information. (This application is no relation to Apple's iCal product or the iCalendar data exchange standard.)

The icalparse project arose from the author's need to salvage historical information from his ical appointments, including important dates such as birthdays.

The format of the .calendar file that this application uses to store its information is a rather unusual free-field format using [ square brackets ] to group data. This reduces the problem of data extraction to parsing problem, using a context-free grammar. Python's pyparsing module makes it easy to implement a recursive descent parser. This tool has much more power than regular-expression-based approaches, but requires considerably less infrastructure than a full-blown compiler.

This project has, then, two purposes. It is a tool for others who may wish to extract data from their .calendar files. It is also a demonstration of the power and simplicity of pyparsing.