Created
April 9, 2024 09:12
-
-
Save bennokr/6d87dfd08e8974d6d581117c51a54034 to your computer and use it in GitHub Desktop.
Annotate literature search results
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request, abort, render_template | |
app = Flask(__name__, template_folder='.') | |
import gspread | |
import textwrap | |
gc = gspread.oauth( | |
credentials_filename='credentials.json', | |
authorized_user_filename='authorized_user.json' | |
) | |
sh = gc.open_by_key('') # INSERT DOC KEY HERE | |
ws = sh.sheet1 | |
print('Opened spreadsheet, size: ', ws.col_count, '*', ws.row_count) | |
n_rows = ws.row_count | |
@app.route("/") | |
def index(): | |
colnr_user = int(request.args.get("user", 0)) | |
if colnr_user: | |
annotations = ws.col_values(colnr_user) | |
annotations += [''] * (n_rows - len(annotations)) | |
rownr = int(request.args.get("rownr", 0)) | |
new_annotation = int(request.args.get("annotation", 0)) | |
if rownr and new_annotation: | |
annotations[rownr-1] = new_annotation | |
ws.update_cell(rownr, colnr_user, new_annotation) | |
rownr_first_empty = next(i+1 for i, v in enumerate(annotations) if not v) | |
title = ws.cell(rownr_first_empty, 6).value | |
abs = ws.cell(rownr_first_empty, 18).value | |
return render_template( | |
'index.html', | |
user=colnr_user, | |
rownr=rownr_first_empty, | |
title=title, | |
abstract=abs, | |
) | |
else: | |
return render_template( | |
'index.html', | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head><title>scopus annotate</title></head> | |
<style> | |
body { font-family: sans-serif; } | |
#main {margin: 0 auto; max-width: 800px;} | |
textarea { width: 100%; height: 8em } | |
</style> | |
<body> | |
<div id="main"> | |
<form id="annotate"> | |
{% if user %} | |
<h1>{{title}}</h1> | |
<p> | |
{{abstract}} | |
</p> | |
<input type="hidden" name="rownr" value="{{rownr}}" /> | |
<input type="hidden" name="user" value="{{user}}" /> | |
<input type="hidden" name="annotation" value="0" /> | |
<input type="submit" value="Include" onclick="window.annotate.annotation.value=1" /> | |
<input type="submit" value="Exclude" onclick="window.annotate.annotation.value=-1" /> | |
<input type="submit" value="Skip" /> | |
{% else %} | |
<input type="hidden" name="user" value="" /> | |
<input type="submit" value="Name 1" onclick="window.annotate.user.value=1" /> | |
<input type="submit" value="Name 2" onclick="window.annotate.user.value=2" /> | |
{% endif %} | |
</form> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
perfect