-
Notifications
You must be signed in to change notification settings - Fork 0
/
babel.py
84 lines (68 loc) · 2.35 KB
/
babel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Copyright (C) 2001 - 2024 David Fillmore
#
# This file is part of ififf.
#
# ififf 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 2 of the License, or
# (at your option) any later version.
#
# ififf is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
from xml.dom.minidom import parseString
def getbibliographic(iFiction):
dom = parseString(iFiction)
try:
story = dom.getElementsByTagName('story')[0] # assumes only one story element
biblio = story.getElementsByTagName('bibliographic')[0]
except:
return None
return biblio
def getTitle(iFiction):
try:
biblio = getbibliographic(iFiction)
title = biblio.getElementsByTagName('title')[0]
return title.childNodes[0].wholeText
except:
return None
def getHeadline(iFiction):
try:
biblio = getbibliographic(iFiction)
headline = biblio.getElementsByTagName('headline')[0]
return headline.childNodes[0].wholeText
except:
return None
def getAuthor(iFiction):
try:
biblio = getbibliographic(iFiction)
author = biblio.getElementsByTagName('author')[0]
return author.childNodes[0].wholeText
except:
return None
def getDescription(iFiction):
try:
biblio = getbibliographic(iFiction)
desc = biblio.getElementsByTagName('description')[0]
fulldesc = []
return ''.join([ ('\n\n' if a.nodeType == 1 and a.localName == 'br' else ' '.join(a.wholeText.split())) for a in desc.childNodes
]
)
except:
return None
def getZcode(iFiction):
try:
dom = parseString(iFiction)
story = dom.getElementsByTagName('story')[0] # assumes only one story element
zcode = story.getElementsByTagName('zcode')[0]
return zcode
except:
return None
def getCoverPicture(iFiction):
zcode = getZcode(iFiction)
try:
coverpicture = zcode.getElementsByTagName('coverpicture')
return int(coverpicture[0].childNodes[0].wholeText)
except:
return None