From f42632a4513a35f5bf0aac2e1d4c9da1e75d4a4a Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Wed, 10 Feb 2016 16:17:19 +0100 Subject: [PATCH] Style it a bit. --- main.py | 23 ++++++++++++++------ views/template.tpl | 54 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 68 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index 552ea0a..baca1e1 100755 --- a/main.py +++ b/main.py @@ -1,10 +1,13 @@ #!/usr/bin/env python3 import config -from libbmc.citations import pdf +import html +import json import os import tempfile from bottle import redirect, request, route, run, view +from libbmc import doi +from libbmc.citations import pdf @route("/upload", method="POST") @@ -30,12 +33,21 @@ def do_upload(): # Process citations with tempfile.NamedTemporaryFile() as fh: upload.save(fh) - citations = pdf.cermine_dois(fh.name, - override_local=config.CERMINE_PATH) + raw_citations = pdf.cermine_dois(fh.name, + 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 { "params": { - "citations": citations + "citations": citations, + "upload_name": upload.filename } } @@ -55,8 +67,7 @@ def index(): Main index view, upload form. """ return { - "params": { - } + "params": {} } diff --git a/views/template.tpl b/views/template.tpl index 10b97c6..d8ac27c 100644 --- a/views/template.tpl +++ b/views/template.tpl @@ -3,18 +3,66 @@ CitationExtractor + + +

Citation Extractor

+ %if "error" in params:

Error: {{ params["error"] }}

% end % if "citations" in params: -
{{ params["citations"] }}
+

Extracted citations for your paper {{ params["upload_name"] }} (not that some citations may have not been extracted properly):

+
+
+ % for k, v in params["citations"].items(): +
• {{ k }}
+
> + % if v["doi"] is not None: + doi://{{ v["doi"] }} + % else: + No DOI found. + % end +
+
> + % if v["oa"] is not None: + {{ v["oa"] }} + % else: + No OpenAccess version found. + % end +
+ % end +
% else: +

This tool allows you to extract citations from a given PDF paper. Upload a file below and let it process your paper!

+
-

-

+

% end