Extract and Parse ODF Files with Python

 in
Use Python to demystify Open Document Format files.

Kamran Husain has been working with software for 20 years. He can be contacted at khusain62@yahoo.com.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

File is not a zip file

hypertex's picture

I am trying to run listing 5. Am I the only one receiving this error?


File "./odt.py", line 13, in __init__
self.m_odf = zipfile.ZipFile(filename)
File "/usr/lib/python2.6/zipfile.py", line 693, in __init__
self._GetContents()
File "/usr/lib/python2.6/zipfile.py", line 713, in _GetContents
self._RealGetContents()
File "/usr/lib/python2.6/zipfile.py", line 725, in _RealGetContents
raise BadZipfile, "File is not a zip file"
zipfile.BadZipfile: File is not a zip file

and yet . . .

>>> odfname = ('bill_of_rights.odt')
>>> zipfile.is_zipfile(odfname)
True

I'm confused is_zipfile() returns true, but I get a BadZipfile exception. Same result with several different files, so I don't think it is a bad file. Running python 2.6.4 on fedora 13.

D'OH!

hypertex's picture

the __main__ block should have:

filename = sys.argv[1]
phrase = sys.argv[2]

I keep forgetting that sys.argv[0] is a reference to the script, not the first argument to the script.

LPOD Project

Anonymous's picture

lpod is an ODF library that allow to easily manipulate ODF documents.

Fail? What fail?

Anonymous's picture

To the first commenter, win32 doesn't mean windows 3.2. It means 32-bit windows.
(Windows NT/2000/XP/Vista/7)

FAIL!

Anonymous's picture

Python 2.4.1 (#65, Mar 30 2005, 09:13:57)
[MSC v.1310 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()"
for more information.

however, very good tutorial doh! ;)

greets
Royma

Nice

Nichoals's picture

Nice tutorials.. You'r the only one in the net that write something aboute odt and python clearly.
Do you have a tutorials to pick pictures from the odt file too?

uçak bileti

uçak bileti's picture

Have read all of the posts. Very interesting and much better disciplined than most sessions. and thank you for information.

Plug-in For MS Office

W^L+'s picture

Instead of the ODF-Converter project on SourceForge, with its well-known flaws (cannot set ODF formats as default formats for MS Office, poor fidelity between original file and the imported/exported version, ODF placed in separate submenu instead of the usual file->save as, and intermediate saves still require long export process), I'd recommend Sun's plugin for MS Office. It features much better integration with MS Office and better fidelity import/export.

Either one will trigger warnings about the format not being fully compatible, but for most purposes, ODF is fully-capable of representing MS Office data.

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix