Home | Trees | Indices | Help |
|
---|
|
1 #!/usr/bin/python 2 # -*- coding: UTF-8 -*- 3 # 4 #The MIT License 5 # 6 #Copyright (c) 2011 7 # 8 #Permission is hereby granted, free of charge, to any person obtaining a copy 9 #of this software and associated documentation files (the "Software"), to deal 10 #in the Software without restriction, including without limitation the rights 11 #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 #copies of the Software, and to permit persons to whom the Software is 13 #furnished to do so, subject to the following conditions: 14 # 15 #The above copyright notice and this permission notice shall be included in 16 #all copies or substantial portions of the Software. 17 # 18 #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 #THE SOFTWARE. 25 # 26 #Authors: 27 # Vili Auvinen (vili.k.auvinen@jyu.fi) 28 # Olli Kauppinen (olli.kauppinen@jyu.fi) 29 # Juho Tammela (juho.i.tammela@jyu.fi) 30 31 ''' The module is for getting Microsoft Office file formats' docx, pptx, and xlsx meta informations. 32 The module is not currently used, but it will be in future development. 33 34 @author: Juho Tammela 35 ''' 36 37 import sys 38 import zipfile 39 from xml.dom import minidom 40 41 42 # def __init__(self, filename): 43 # ''' 44 # filename -- the name or path of the document-file. 45 # ''' 46 # self.filename = filename 47 # 48 # if zipfile.is_zipfile(filename): 49 # mydocument = zipfile.ZipFile(filename) 50 # coreFile = mydocument.read('docProps/core.xml') 51 # self.coreXml = minidom.parseString(coreFile) 52 5355 ''' Returns the text content of the given element. 56 57 elementTagName -- the tag name of the element. 58 59 @return: Thetext content of the element. If no text content is found, returns the error message. 60 ''' 61 if (coreXml): 62 value = "" 63 try: 64 value = coreXml.getElementsByTagName(elementTagName)[0].firstChild.nodeValue 65 except IndexError: 66 return elementTagName + " - tag not found" 67 return value68 72 7678 return getElementValue('dcterms:created', coreXml)7981 return getElementValue('dcterms:modified', coreXml)8284 return getElementValue('cp:revision', coreXml)85 86 87 if __name__ == "__main__": 88 89 filename = 'sampleFiles/docx/Teija_Holtta.docx' 90 91 if zipfile.is_zipfile(filename): 92 mydocument = zipfile.ZipFile(filename) 93 coreFile = mydocument.read('docProps/core.xml') 94 docxCoreXml = minidom.parseString(coreFile) 95 96 # docxMetaReader = MsoMeta("docx_demo.docx") 97 # print docxMetaReader.filename 98 print 'Creator: ' + getCreator(docxCoreXml) 99 print 'Last modified by: ' + getLastModifier(docxCoreXml) 100 print 'Created: ' + getCreateDate(docxCoreXml) 101 print 'Modified: ' + getLastModifiedDate(docxCoreXml) 102 print 'Revision: ' + getRevision(docxCoreXml) 103
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Tue Jun 21 17:30:07 2011 | http://epydoc.sourceforge.net |