Skip to content

Instantly share code, notes, and snippets.

@pferreir
Created August 12, 2016 08:25
Show Gist options
  • Save pferreir/60e3135a9165805ee3b0baf4e1728895 to your computer and use it in GitHub Desktop.
Save pferreir/60e3135a9165805ee3b0baf4e1728895 to your computer and use it in GitHub Desktop.
from lxml import etree
from flask import Flask, request
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
@app.route("/batchuploader/robotupload", methods=("GET",))
def upload_get():
return 'hello'
def _print_records(data):
root = etree.fromstring(data.encode('utf-8'))
ns = {'marc': root.nsmap[None]}
count = 0
for record in root.findall('marc:record', namespaces=ns):
rid = record.find('marc:datafield[@tag="970"]/marc:subfield[@code="a"]', namespaces=ns).text
deleted = record.find('marc:datafield[@tag="980"]/marc:subfield[@code="c"]', namespaces=ns)
if deleted is None:
deleted = False
else:
deleted = deleted.text == 'DELETED'
count += 1
print(("-" if deleted else "+") + " " + rid)
@app.route("/batchuploader/robotupload", methods=("POST",))
def upload_post():
data = request.form['file']
_print_records(data)
return "[INFO] Records uploaded"
@app.route("/cern", methods=("POST",))
def upload_post_xml():
data = request.form['xml']
_print_records(data)
return "<result>true</result>"
if __name__ == "__main__":
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment