Letractively / pytof

Automatically exported from code.google.com/p/pytof
Other
0 stars 1 forks source link

XML parsing error with the date Element #3

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
[100drine@gnocchi trunk]$ python makepage.py -l 
/Users/100drine/Pictures/iPhotoLibrary 
Berkeley
Parsing AlbumData.xmlTraceback (most recent call last):
  File "makepage.py", line 147, in ?
    main(albumName, libraryPath)
  File "makepage.py", line 72, in main
    data = parser.parse()
  File "/Users/100drine/src/pytof/trunk/albumdataparser.py", line 128, in parse
    p.ParseFile(self.xmlFile)
  File "/Users/100drine/src/pytof/trunk/albumdataparser.py", line 98, in start_element
    raise ExpatError, "Element \"%s\" not supported" % name
xml.parsers.expat.ExpatError: Element "date" not supported

Original issue reported on code.google.com by bserg...@gmail.com on 20 Dec 2006 at 4:33

GoogleCodeExporter commented 9 years ago
Adding a report method to print the xml datas parsed may be usefull for 
debugging

Original comment by bserg...@gmail.com on 20 Dec 2006 at 9:37

GoogleCodeExporter commented 9 years ago
Need to add support for date in XmlItem.setValue (albumdataparser.py).

Here is some code I wrote to convert iPhoto date to proper string 
representation:

###
from time import strptime, mktime, strftime, localtime

iPhotoBase = mktime(strptime("2001 01 01 00 00 00", "%Y %m %d %H %M %S"))
testValues = [-12618000.000000, 145631466.000000]

for value in testValues:
    photoTime = localtime(value + iPhotoBase)
    print value, strftime("%d/%m/%Y %H:%M:%S", photoTime)

Original comment by mathieu....@gmail.com on 20 Dec 2006 at 9:37

GoogleCodeExporter commented 9 years ago
From Panther to Tiger, it looks like the time format changed from a standard 
string to a real (float) type, so the 
parser cannot work with old files.

Original comment by bserg...@gmail.com on 20 Dec 2006 at 9:49

GoogleCodeExporter commented 9 years ago
Here is how to reproduce it using the test xml file from test/data

python pytof.py -i -l test/data/ -x AlbumData_gnocchi.xml

Original comment by bserg...@gmail.com on 20 Dec 2006 at 11:31

GoogleCodeExporter commented 9 years ago
Here is another code sample for date parsing:

class dateObjFromStringError: pass
def dateObjFromString(text):
        """ http://pleac.sourceforge.net/pleac_python/datesandtimes.html """
        formats = [
        '%A %d %B %Y %Hh%M', # equipetv
        '%a, %d %b %Y %H:%M:%S PDT', # orm
        '%a, %d %b %Y %H:%M:%S +0200', # radio france
        ]
        for f in formats:
            try:
                timeobject = time.strptime(text, f)
                parsed = True
            except (ValueError): pass

        if not parsed:
            raise dateObjFromStringError

        return timeobject

try:
   self.curLastDate = dateObjFromString(text)
except (dateObjFromStringError):
   self.curLastDate = dateSortedMp3Lister.DC

Original comment by bserg...@gmail.com on 21 Dec 2006 at 12:52

GoogleCodeExporter commented 9 years ago
Fixed in a quite hackish way, there may be a problem ... (so it would be good 
to have
unit testing :)

Original comment by bserg...@gmail.com on 22 Dec 2006 at 10:55