Add Orpheo Serializer and update config.tmpl with empty Orpheo URL
authorrougeronj
Wed, 08 Apr 2015 16:55:19 +0200
changeset 80 86849b3acd3a
parent 79 1be5cc51e359
child 81 ef4d8ed6eef2
Add Orpheo Serializer and update config.tmpl with empty Orpheo URL
server/ammico/serializers.py
server/config.py.tmpl
--- a/server/ammico/serializers.py	Wed Apr 08 00:39:23 2015 +0200
+++ b/server/ammico/serializers.py	Wed Apr 08 16:55:19 2015 +0200
@@ -22,9 +22,13 @@
     
     def getStopInfo(self, slide):
         if (slide.idInventory != ""):
+            #slide added from searched in MIMO database
             return extractFromMIMO(slide)
         else:
-            return extractFromOrpheo(slide)
+            #Get stop info from Oprheo
+            #return extractFromOrpheo(slide)
+            #Get stop info from Jamespot
+            return extractFromJameSpot(slide)
         
     def getOrder(self, slide):
         return slide.book.get_slide_order().index(slide.id)
@@ -42,9 +46,10 @@
     if (len(results['hits']) == 1):
         for i in results['hits'][0]['metas']:
             if('images' not in i):
-                details[i['name']] = i['value']
+                if ('name' in i):
+                    details[i['name']] = i['value']
             else:
-                details['images'] = i['images'][0]['value']           
+                details.setdefault('images', []).append(i['images'][0]['value'])
         details['title'] = details.pop('name')
     return details
 
@@ -54,7 +59,7 @@
     for stops in stopList:
         if (slide.idStop == stops['idStop']):
             details = stops
-            details['images'] = details.pop('firstImg')
+            details.setdefault('images', []).append(details.pop('firstImg'))
             details['description'] = details.pop('captionImg')
     return details
 
@@ -77,14 +82,14 @@
             
         if (parsed_data['result']['item']['Audio']):
             parser.feed(parsed_data['result']['item']['Audio'])
-            details['image']= parser.image
+            details['images']= parser.images
             details['audio']= parser.audio
-            details['caption']= parser.caption
+            details['captions']= parser.captions
             
         if (parsed_data['result']['item']['Video']):
             parser.feed(parsed_data['result']['item']['Video'])
             details['video']= parser.video
-            details['image']= parser.image
+            details['images']= parser.images
             
         #if (parsed_data['result']['item']['Image']):
         #    parser.feed(parsed_data['result']['item']['Image'])
@@ -92,29 +97,36 @@
         
     return details
 
+#HTML parser to get the info from the Orpheo XML
+#Hopefully they'll update it because so far it's too slow
+#to parse the xml and then the html..
+#Better use extractFromJameSpot for now.
 class MyHTMLParser(HTMLParser):
-    starttag=''
-    endtag=''
-    audio=''
-    video=''
-    image=''
-    caption=''
-    description=''
+    
+    def __init__(self):
+        self.starttag=''
+        self.endtag=''
+        self.audio=''
+        self.video=''
+        self.images=[]
+        self.captions=[]
+        self.description=''
+        self.captionList=''
+        HTMLParser.__init__(self)
     
     def handle_starttag(self, tag, attrs):
         if (self.starttag == 'audio' and tag == 'source'):
             for attr in attrs:
                 if 'src' in attr:
-                    print(attr)
                     self.audio = attr[1]
         elif (tag == 'img'):
             for attr in attrs:
                 if 'src' in attr:
-                    self.image = attr[1]
+                    self.images.append(attr[1])
         elif (tag == 'video'):
             for attr in attrs:
                 if 'poster' in attr:
-                    self.image = attr[1]
+                    self.images.append(attr[1])
         if (self.starttag == 'video' and tag == 'source'):
             for attr in attrs:
                 if 'src' in attr:
@@ -124,4 +136,9 @@
     def handle_endtag(self, tag):
         self.tag = tag
     def handle_data(self, data):
-        self.description = data
+        if ('Caption_image' in data):
+            self.captionList = True
+        elif (self.captionList == True):
+            self.captions.append(data)
+        else:
+            self.description = data
\ No newline at end of file
--- a/server/config.py.tmpl	Wed Apr 08 00:39:23 2015 +0200
+++ b/server/config.py.tmpl	Wed Apr 08 16:55:19 2015 +0200
@@ -15,4 +15,6 @@
 # SECURITY WARNING: keep the secret key used in production secret!
 SECRET_KEY = ''
 
-URL_JAMESPOT = 'http://fui-ammico.jamespot.pro/api/api.php?&k=API-KEY&d=YYYY-MM-DD&m=EXT-API&v=2.0'
\ No newline at end of file
+URL_JAMESPOT = 'http://fui-ammico.jamespot.pro/api/api.php?&k=API-KEY&d=YYYY-MM-DD&m=EXT-API&v=2.0'
+URL_EXALEAD = ''
+URL_ORPHEO = ''
\ No newline at end of file