summaryrefslogtreecommitdiffstats
path: root/src/translators/griffith2tellico.py
diff options
context:
space:
mode:
authorSlávek Banko <[email protected]>2023-01-20 22:54:25 +0100
committerSlávek Banko <[email protected]>2023-01-20 22:54:25 +0100
commitc800d114bf78f9526834ddafa8ef5a1c2e063d8e (patch)
tree776fb2fb0bd8f146c2b9a7ba7e62731e3db6c764 /src/translators/griffith2tellico.py
parentb2ccda8be812a3c5c236bda0eacde37756b8551c (diff)
downloadtellico-c800d114bf78f9526834ddafa8ef5a1c2e063d8e.tar.gz
tellico-c800d114bf78f9526834ddafa8ef5a1c2e063d8e.zip
Drop python2 support.r14.1.0
Signed-off-by: Slávek Banko <[email protected]>
Diffstat (limited to 'src/translators/griffith2tellico.py')
-rwxr-xr-xsrc/translators/griffith2tellico.py52
1 files changed, 26 insertions, 26 deletions
diff --git a/src/translators/griffith2tellico.py b/src/translators/griffith2tellico.py
index 24bfb41..ccba70a 100755
--- a/src/translators/griffith2tellico.py
+++ b/src/translators/griffith2tellico.py
@@ -21,7 +21,7 @@ import xml.dom.minidom
try:
import sqlite3
except:
- print sys.stderr, "The Python sqlite3 module is required to import Griffith databases."
+ print(sys.stderr, "The Python sqlite3 module is required to import Griffith databases.")
exit(1)
DB_PATH = os.environ['HOME'] + '/.griffith/griffith.db'
@@ -36,7 +36,7 @@ class BasicTellicoDOM:
self.__root = self.__doc.createElement('tellico')
self.__root.setAttribute('xmlns', 'http://periapsis.org/tellico/')
self.__root.setAttribute('syntaxVersion', '9')
-
+
self.__collection = self.__doc.createElement('collection')
self.__collection.setAttribute('title', 'Griffith Import')
self.__collection.setAttribute('type', '3')
@@ -45,7 +45,7 @@ class BasicTellicoDOM:
# Add all default (standard) fields
self.__dfltField = self.__doc.createElement('field')
self.__dfltField.setAttribute('name', '_default')
-
+
# change the rating to have a maximum of 10
self.__ratingField = self.__doc.createElement('field')
self.__ratingField.setAttribute('name', 'rating')
@@ -63,7 +63,7 @@ class BasicTellicoDOM:
propNode.setAttribute('name', 'minimum')
propNode.appendChild(self.__doc.createTextNode('1'))
self.__ratingField.appendChild(propNode);
-
+
# Add a custom 'Original Title' field
self.__titleField = self.__doc.createElement('field')
self.__titleField.setAttribute('name', 'orig-title')
@@ -73,7 +73,7 @@ class BasicTellicoDOM:
self.__titleField.setAttribute('format', '1')
self.__titleField.setAttribute('type', '1')
self.__titleField.setAttribute('i18n', 'yes')
-
+
self.__keywordField = self.__doc.createElement('field')
self.__keywordField.setAttribute('name', 'keyword')
self.__keywordField.setAttribute('title', 'Keywords')
@@ -98,13 +98,13 @@ class BasicTellicoDOM:
self.__fields.appendChild(self.__keywordField)
self.__fields.appendChild(self.__urlField)
self.__collection.appendChild(self.__fields)
-
+
self.__images = self.__doc.createElement('images')
self.__root.appendChild(self.__collection)
self.__doc.appendChild(self.__root)
self.__fieldsMap = dict(country='nationality',
- classification='certification',
+ classification='certification',
runtime='running-time',
o_title='orig-title',
notes='comments',
@@ -121,7 +121,7 @@ class BasicTellicoDOM:
# make sure unique
set = {}
media = [set.setdefault(e,e) for e in orig_media if e not in set]
-
+
mediaField = self.__doc.createElement('field')
mediaField.setAttribute('name', 'medium')
mediaField.setAttribute('title', 'Medium')
@@ -140,17 +140,17 @@ class BasicTellicoDOM:
entryNode = self.__doc.createElement('entry')
entryNode.setAttribute('id', movieData['id'])
- for key, values in movieData.iteritems():
+ for key, values in movieData.items():
if key == 'id':
continue
-
- if self.__fieldsMap.has_key(key):
+
+ if key in self.__fieldsMap:
field = self.__fieldsMap[key]
else:
field = key
parentNode = self.__doc.createElement(field + 's')
-
+
for value in values:
if len(value) == 0: continue
node = self.__doc.createElement(field)
@@ -163,18 +163,18 @@ class BasicTellicoDOM:
imageNode.appendChild(self.__doc.createTextNode(value[1]))
self.__images.appendChild(imageNode)
value = value[0] # value was (id, md5)
-
+
if field == 'cast':
for v in value:
columnNode = self.__doc.createElement('column')
columnNode.appendChild(self.__doc.createTextNode(v.strip()))
node.appendChild(columnNode)
-
+
else:
node.appendChild(self.__doc.createTextNode(value.strip()))
-
+
if node.hasChildNodes(): parentNode.appendChild(node)
-
+
if parentNode.hasChildNodes(): entryNode.appendChild(parentNode)
self.__collection.appendChild(entryNode)
@@ -184,8 +184,8 @@ class BasicTellicoDOM:
Outputs XML content to stdout
"""
self.__collection.appendChild(self.__images)
- print XML_HEADER; print DOCTYPE
- print self.__root.toxml()
+ print(XML_HEADER); print(DOCTYPE)
+ print(self.__root.toxml())
class GriffithParser:
@@ -210,7 +210,7 @@ class GriffithParser:
media = list([row[0].encode('utf-8') for row in c.fetchall()])
self.__domTree.addMedia(media)
-
+
def __fetchMovieIds(self):
"""
Retrieve all movie ids
@@ -230,7 +230,7 @@ class GriffithParser:
'country','genre','classification','plot',
'runtime','o_title','studio','notes','image',
'[cast]','loaned','color','site')
-
+
c = self.__conn.cursor()
c.execute("SELECT %s FROM movies WHERE movie_id=%s" % (','.join(columns),id))
row = c.fetchone()
@@ -240,14 +240,14 @@ class GriffithParser:
for i in range(len(columns)):
if row[i] == None : continue
-
+
try:
value = row[i].encode('utf-8')
except:
value = str(row[i])
-
+
col = columns[i].replace('[','').replace(']','')
-
+
if col == 'genre' or col == 'studio':
values = value.split('/')
elif col == 'plot' or col == 'notes':
@@ -280,19 +280,19 @@ class GriffithParser:
media = list([row[0].encode('utf-8') for row in c.fetchall()])
if len(media) > 0: data['medium'] = media
-
+
# get all tags
c.execute("SELECT name FROM tags WHERE tag_id IN (SELECT tag_id FROM movie_tag WHERE movie_id=%s)" % id)
tags = list([row[0].encode('utf-8') for row in c.fetchall()])
if len(tags) > 0: data['tag'] = tags
-
+
# get all languages
c.execute("SELECT name FROM languages WHERE lang_id IN (SELECT lang_id FROM movie_lang WHERE movie_id=%s)" % id)
langs = list([row[0].encode('utf-8') for row in c.fetchall()])
if len(langs) > 0: data['language'] = langs
-
+
return data