Skip to content
Snippets Groups Projects

Resolve "BiblioAPI"

Merged Michelle Weidling requested to merge 13-biblioapi into develop
All threads resolved!
1 file
+ 17
1
Compare changes
  • Side-by-side
  • Inline
+ 17
1
import json
from os.path import exists
from pathlib import Path
from fastapi import FastAPI, Request
from fastapi import FastAPI, Request, Response
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse, HTMLResponse
from collection import make_collection
@@ -109,6 +109,22 @@ def get_zotero_entry(zotero_id: str):
return [e[zotero_id] for e in data if zotero_id in e][0]
@app.get('/api/eupt/biblio/xml/{zotero_id}')
def get_zotero_entry_as_xml(zotero_id: str):
"""
Returns the marked up bibliographic entry for a given Zotero item in XML format.
This is needed for our XSLTs to work smoothly.
Args:
- zotero_id: the ID of the Zotero item
"""
with open('assets/json/eupt-bibliography.json', mode='r', encoding='utf-8') as f:
data = json.loads(f.read())
entry = [e[zotero_id] for e in data if zotero_id in e][0]
xml_data = f'<?xml version="1.0"?><bibl>{entry}</bibl>'
return Response(content=xml_data, media_type="application/xml")
def fix_base_url_protocol(base_url: str) -> str:
"""
request.base_url returns the http protcol instead of https which results
Loading