Skip to content
Snippets Groups Projects
Select Git revision
  • 80df282efc0e6191c35dc7dfcd9ee513a2cbef37
  • master default protected
2 results

api.py

Blame
  • moogdo49's avatar
    moogdo49 authored
    	geändert:               templates/index.html
    80df282e
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    api.py 4.90 KiB
    from flask import Flask, request, jsonify, make_response, g, render_template
    from flask_cors import CORS
    import BaseXClient
    import threading
    import xml.etree.ElementTree as ET
    import xml.dom.minidom as dom
    
    
    app = Flask(__name__)
    CORS(app)
    session = BaseXClient.Session('localhost', 1984, 'admin', 'admin')
    
    @app.route('/', methods=['GET'])
    def main():
        #globvar = session.query("db:open(\"Holzschnitt\")")
        session.execute("open Holzschnitt")
        merke = []
        
        for i in range(1,5):
        	url = session.query("declare namespace lido=\"http://www.lido-schema.org\"; for $x in (/root/object[position() =" + str(i) +" ]/bildLink/text()) return $x" ).execute()
        	actor = session.query("declare namespace lido=\"http://www.lido-schema.org\"; for $x in (/root/object[position() =" + str(i) +" ]/descriptiveMetadata/actor/text()) return $x" ).execute()
        	title = session.query("declare namespace lido=\"http://www.lido-schema.org\"; for $x in (/root/object[position() =" + str(i) +" ]/descriptiveMetadata/objectIdentificationWrap/title/text()) return $x" ).execute()
        	eintrag = {"url" : url, "actor" : actor, "title" : title}
        	merke.append(eintrag)
    
        	
        #tree = ET.parse(globvar)
        #root = tree.root()
        #globvar = "ws"
        #session.query("db:open(\"Holzschnitt\")").execute()
    
    
        return render_template('index.html', objects = merke, searchBool = False, text = '')
    
    @app.route('/search', methods=['POST', 'GET'])
    def search():
    	if request.method=='GET':
    		merke = []
    		for i in range(1,5):
    			url = session.query("declare namespace lido=\"http://www.lido-schema.org\"; for $x in (/root/object[position() =" + str(i) +" ]/bildLink/text()) return $x" ).execute()
    			actor = session.query("declare namespace lido=\"http://www.lido-schema.org\"; for $x in (/root/object[position() =" + str(i) +" ]/descriptiveMetadata/actor/text()) return $x" ).execute()
    			title = session.query("declare namespace lido=\"http://www.lido-schema.org\"; for $x in (/root/object[position() =" + str(i) +" ]/descriptiveMetadata/objectIdentificationWrap/title/text()) return $x" ).execute()
    			eintrag = {"url" : url, "actor" : actor, "title" : title}
    			merke.append(eintrag)
    
    		return render_template('index.html', objects = merke, searchBool = False, text = '')
    
    	text = request.form['holzschnitte']
    	#suche nach Künstler:
    	#query = session.query("declare namespace lido=\"http://www.lido-schema.org\"; for $x in (/root/object[descriptiveMetadata/actor[contains(text(), " + text + ")]]) return $x")
    	merke = []
    	urlQuery = session.query("declare namespace lido=\"http://www.lido-schema.org\"; for $x in (/root/object[descriptiveMetadata/actor[contains(text(),'" + text + "')]]/bildLink/text()) return $x")
    	actorQuery = session.query("declare namespace lido=\"http://www.lido-schema.org\"; for $x in (/root/object[descriptiveMetadata/actor[contains(text(),'" + text + "')]]/descriptiveMetadata/actor/text()) return $x")
    	titleQuery = session.query("declare namespace lido=\"http://www.lido-schema.org\"; for $x in (/root/object[descriptiveMetadata/actor[contains(text(),'" + text + "')]]/descriptiveMetadata/objectIdentificationWrap/title/text()) return $x")
    	urlList = []
    	actorList = []
    	titleList = []
    
    	for a,url in urlQuery.iter():
    		urlList.append(url)
    
    	for b,actor in actorQuery.iter():
    		actorList.append(actor)
    
    	for c,title in titleQuery.iter():
    		titleList.append(title)
    
    
    	for i in range(0, len(urlList)):
    		url = urlList[i]
    		actor = actorList[i]
    		title = titleList[i]
    		eintrag = {"url" : url, "actor" : actor, "title" : title}
    		merke.append(eintrag)
    
    	urlQuery.close()
    	actorQuery.close()
    	titleQuery.close()
    	
    	#Suche nach Titel:
    	urlQuery = session.query("declare namespace lido=\"http://www.lido-schema.org\"; for $x in (/root/object[descriptiveMetadata/objectIdentificationWrap/title[contains(text(),'" + text + "')]]/bildLink/text()) return $x")
    	actorQuery = session.query("declare namespace lido=\"http://www.lido-schema.org\"; for $x in (/root/object[descriptiveMetadata/objectIdentificationWrap/title[contains(text(),'" + text + "')]]/descriptiveMetadata/actor/text()) return $x")
    	titleQuery = session.query("declare namespace lido=\"http://www.lido-schema.org\"; for $x in (/root/object[descriptiveMetadata/objectIdentificationWrap/title[contains(text(),'" + text + "')]]/descriptiveMetadata/objectIdentificationWrap/title/text()) return $x")
    	urlList = []
    	actorList = []
    	titleList = []
    
    	for a,url in urlQuery.iter():
    		urlList.append(url)
    
    	for b,actor in actorQuery.iter():
    		actorList.append(actor)
    
    	for c,title in titleQuery.iter():
    		titleList.append(title)
    
    
    	for i in range(0, len(urlList)):
    		url = urlList[i]
    		actor = actorList[i]
    		title = titleList[i]
    		eintrag = {"url" : url, "actor" : actor, "title" : title}
    		merke.append(eintrag)
    
    	urlQuery.close()
    	actorQuery.close()
    	titleQuery.close()
    
    	return render_template('index.html', objects = merke, searchBool = True, text = text)
    
    
    if __name__ == "__main__":
        app.run(host="0.0.0.0", port=5000, debug=True)