From 81a82573dc78a8cbf2f86100043f74f1305f4c56 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Mon, 18 Mar 2019 16:09:13 -0700 Subject: expose bibtex and citeproc; revert /unstable/ prefixes --- python/fatcat_tools/transforms/csl.py | 2 +- python/fatcat_web/routes.py | 35 +++++++++++++++++++++++++++++++--- python/fatcat_web/templates/stats.html | 2 +- 3 files changed, 34 insertions(+), 5 deletions(-) (limited to 'python') diff --git a/python/fatcat_tools/transforms/csl.py b/python/fatcat_tools/transforms/csl.py index 3509f350..7bc026ed 100644 --- a/python/fatcat_tools/transforms/csl.py +++ b/python/fatcat_tools/transforms/csl.py @@ -208,7 +208,7 @@ def citeproc_csl(csl_json, style, html=False): bib.register(Citation([CitationItem(csl_json['id'])])) lines = bib.bibliography()[0] if style == "bibtex": - out = "\n" + out = "" for l in lines: if l.startswith(" @"): out += "@" diff --git a/python/fatcat_web/routes.py b/python/fatcat_web/routes.py index d660da86..e2c5fc3a 100644 --- a/python/fatcat_web/routes.py +++ b/python/fatcat_web/routes.py @@ -2,7 +2,7 @@ import os import json from flask import Flask, render_template, send_from_directory, request, \ - url_for, abort, g, redirect, jsonify, session, flash + url_for, abort, g, redirect, jsonify, session, flash, Response from flask_login import login_required from fatcat_client.rest import ApiException @@ -507,7 +507,7 @@ def stats_page(): ### Pseudo-APIs ############################################################# -@app.route('/unstable/stats.json', methods=['GET', 'OPTIONS']) +@app.route('/stats.json', methods=['GET', 'OPTIONS']) @crossdomain(origin='*',headers=['access-control-allow-origin','Content-Type']) def stats_json(): try: @@ -518,7 +518,6 @@ def stats_json(): abort(503) return jsonify(stats) -@app.route('/unstable/container/issnl//stats.json', methods=['GET', 'OPTIONS']) @app.route('/container/issnl//stats.json', methods=['GET', 'OPTIONS']) @crossdomain(origin='*',headers=['access-control-allow-origin','Content-Type']) def container_issnl_stats(issnl): @@ -529,6 +528,36 @@ def container_issnl_stats(issnl): abort(503) return jsonify(stats) +@app.route('/release/.bib', methods=['GET']) +def release_bibtex(ident): + try: + entity = api.get_release(ident) + except ApiException as ae: + abort(ae.status) + csl = release_to_csl(entity) + bibtex = citeproc_csl(csl, 'bibtex') + return Response(bibtex, mimetype="text/plain") + +@app.route('/release//citeproc', methods=['GET']) +def release_citeproc(ident): + style = request.args.get('style', 'harvard1') + is_html = request.args.get('html', False) + if is_html and is_html.lower() in ('yes', '1', 'true', 'y', 't'): + is_html = True + else: + is_html = False + + try: + entity = api.get_release(ident) + except ApiException as ae: + abort(ae.status) + csl = release_to_csl(entity) + cite = citeproc_csl(csl, style, is_html) + if is_html: + return Response(cite) + else: + return Response(cite, mimetype="text/plain") + ### Auth #################################################################### diff --git a/python/fatcat_web/templates/stats.html b/python/fatcat_web/templates/stats.html index 7f56248f..f11ca820 100644 --- a/python/fatcat_web/templates/stats.html +++ b/python/fatcat_web/templates/stats.html @@ -3,7 +3,7 @@

Stats

-You can also fetch these numbers as JSON. +You can also fetch these numbers as JSON.

Changelog

-- cgit v1.2.3