Style it a bit.

This commit is contained in:
Lucas Verney 2016-02-10 16:17:19 +01:00
parent c62d56684d
commit f42632a451
2 changed files with 68 additions and 9 deletions

23
main.py
View File

@ -1,10 +1,13 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import config import config
from libbmc.citations import pdf import html
import json
import os import os
import tempfile import tempfile
from bottle import redirect, request, route, run, view from bottle import redirect, request, route, run, view
from libbmc import doi
from libbmc.citations import pdf
@route("/upload", method="POST") @route("/upload", method="POST")
@ -30,12 +33,21 @@ def do_upload():
# Process citations # Process citations
with tempfile.NamedTemporaryFile() as fh: with tempfile.NamedTemporaryFile() as fh:
upload.save(fh) upload.save(fh)
citations = pdf.cermine_dois(fh.name, raw_citations = pdf.cermine_dois(fh.name,
override_local=config.CERMINE_PATH) override_local=config.CERMINE_PATH)
citations = {
html.unescape(k): {
"doi": doi.to_canonical(v) if v is not None else v,
"oa": doi.get_oa_version(doi.to_canonical(v) if v is not None
else v)
}
for k, v in raw_citations.items()
}
return { return {
"params": { "params": {
"citations": citations "citations": citations,
"upload_name": upload.filename
} }
} }
@ -55,8 +67,7 @@ def index():
Main index view, upload form. Main index view, upload form.
""" """
return { return {
"params": { "params": {}
}
} }

View File

@ -3,18 +3,66 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<title>CitationExtractor</title> <title>CitationExtractor</title>
<style>
body {
margin: auto;
width: 75%;
}
h1 a {
text-decoration: none;
color: black;
}
dl {
margin-top: 2em;
}
form {
padding-left: 25%;
margin-top: 2em;
}
dt:not(:first-child) {
margin-top: 1em;
}
</style>
</head> </head>
<body> <body>
<h1><a href="/">Citation Extractor</a></h1>
%if "error" in params: %if "error" in params:
<p><strong>Error: {{ params["error"] }}</strong></p> <p><strong>Error: {{ params["error"] }}</strong></p>
% end % end
% if "citations" in params: % if "citations" in params:
<pre>{{ params["citations"] }}</pre> <p>Extracted citations for your paper <code>{{ params["upload_name"] }}</code> (not that some citations may have not been extracted properly):</p>
<hr/>
<dl>
% for k, v in params["citations"].items():
<dt>• {{ k }}</dt>
<dd>>
% if v["doi"] is not None:
<a href="http://dx.doi.org/{{v["doi"]}}">doi://{{ v["doi"] }}</a>
% else:
<em>No DOI found.</em>
% end
</dd>
<dd>>
% if v["oa"] is not None:
<a href="{{ v["oa"] }}">{{ v["oa"] }}</a>
% else:
<em>No OpenAccess version found.</em>
% end
</dd>
% end
</dl>
% else: % else:
<p>This tool allows you to extract citations from a given PDF paper. Upload a file below and let it process your paper!</p>
<hr/>
<form action="/upload" method="post" enctype="multipart/form-data"> <form action="/upload" method="post" enctype="multipart/form-data">
<p><label for="upload">Select a file: </label><input type="file" name="upload" id="upload" /></p> <p><input type="file" name="upload" id="upload" /> <span style="margin-left: 5em"><input type="submit" value="Extract citations!" /></span></p>
<p><input type="submit" value="Extract citations!" /></p>
</form> </form>
% end % end
</form> </form>