Skip to content

New api #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions cce_search/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ def create_app(test_config=None):
app.config.from_mapping(
SECRET_KEY='dev',
#DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'),
API='http://sfr-bardo-copyright-development.us-east-1.elasticbeanstalk.com',
API='http://localhost:5000/',
# API='http://sfr-bardo-copyright-development.us-east-1.elasticbeanstalk.com',
)

if test_config is None:
Expand All @@ -34,11 +35,10 @@ def create_app(test_config=None):
@app.route('/about')
def about():
return render_template('about.html')

@app.route('/results')
def results():
return render_template('results.html')


@app.route('/help')
def help():
return render_template('help.html')

# a simple page that says hello
@app.route('/registration-classes')
Expand Down
10 changes: 10 additions & 0 deletions cce_search/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
from flask import current_app, g
import requests

def new_search(param, page=0, per_page=10):
r = requests.get(current_app.config['API'] + '/search/multi',
params={'title': param["title"],
'authors': param["authors"],
'publishers': param["publishers"],
'source': 'true',
'page': page,
'per_page': per_page})
return r.json()

def search(term, page=0, per_page=10):
r = requests.get(current_app.config['API'] + '/search/fulltext',
params={'query': term,
Expand Down
76 changes: 40 additions & 36 deletions cce_search/search.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from cce_search.api import search, reg_search, ren_search, registration, renewal
from cce_search.api import search, reg_search, ren_search, new_search, registration, renewal
from flask import (
Blueprint, flash, g, redirect, render_template, request, url_for
)
import re
from urllib.parse import urlparse, parse_qs, parse_qsl, urlunparse, urlencode
from werkzeug.exceptions import abort
from requests import HTTPError
import json

bp = Blueprint('search', __name__)

Expand All @@ -17,56 +18,59 @@ def index():
sentTitle = None
search_type = "ft"
arguments = request.args.get("title") or request.args.get("renewal") or request.args.get("registration") or request.args.get("author") or request.args.get("publisher")
#print("TEST HERE")
#print(request.args)
#print(request.args.get("title"))
print("----------------------------------------------------------")
tempResults = None
tempPaging = None
tempArgs = None
matched_results = []
params = {}
unique = 0
max_page = 0

author = None
publisher = None

if not arguments:
print("NO ARGUMENTS GIVEN. PLEASE GIVE ARGUMENTS")
else:
if request.args.get("renewal"):
results = ren_search(request.args['renewal'], request.args.get('page'),
request.args.get('per_page'))
results = ren_search(request.args['renewal'], request.args.get('page'), request.args.get('per_page'))
paging = proc_pagination(results['data']['paging'], request.args.get('page'))
unique = 1


if request.args.get("registration") and unique == 0:
results = reg_search(request.args['registration'], request.args.get('page'),
request.args.get('per_page'))
results = reg_search(request.args['registration'], request.args.get('page'), request.args.get('per_page'))
paging = proc_pagination(results['data']['paging'], request.args.get('page'))
unique = 1 #technically not 100% unique but should be very simplified for now

if request.args.get("title") and unique == 0:
title = request.args['title']
results = search(title, request.args.get('page'),
request.args.get('per_page'))
paging = proc_pagination(results['data']['paging'],
request.args.get('page'))
unique = 1

if request.args.get("title") and unique==0:
params["title"] = request.args['title']
else:
params["title"] = "*"

if request.args.get("author") and unique == 0:
results = search(request.args['author'], request.args.get('page'),
request.args.get('per_page'))
paging = proc_pagination(results['data']['paging'],
request.args.get('page'))


if request.args.get("publisher") and unique == 0:
results = search(request.args['publisher'], request.args.get('page'),
request.args.get('per_page'))
paging = proc_pagination(results['data']['paging'],
request.args.get('page'))
#paging = proc_pagination(results['data']['paging'],
# request.args.get('page'))

print("PRINTING PAGING HERE")
print(paging)

params["authors"] = request.args['author']
else:
params["authors"] = "*"

if request.args.get("publisher") and unique==0:
params['publishers'] = request.args['publisher']
else:
params["publishers"] = "*"

if unique==0:
results = new_search(params, request.args.get('page'), request.args.get('per_page'))
paging = proc_pagination(results['data']['paging'], request.args.get('page'))

# print("PRINTING PAGING HERE")
# print(paging)
# print("----------------------------------------------------------")
# print("DATA PAGING")
# print(results['data']['paging'])
# print(json.dumps(results))
# print("")
results = proc_results(results)
print(results)
print(json.dumps(results))
print(json.dumps(results[0]["renewals"]))

if results == []:
print("NO RESULTS")
Expand Down
3 changes: 3 additions & 0 deletions cce_search/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
<li class="nav-item active">
<a class="nav-link" href="https://www.nypl.org/">NYPL <span class="sr-only"></span></a>
</li>
<li class="nav-item active">
<a class="nav-link" href="/help">Help <span class="sr-only"></span></a>
</li>
</ul>
</div>
</nav>
Expand Down
19 changes: 19 additions & 0 deletions cce_search/templates/help.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends 'base.html' %}

{% block content %}
<div class="py-5 text-center">
<div class="content">
<h1>Need Help? (IN PROGRESS)</h1>
<p>Enter a Title, Author, Publisher, Registration Number, Renewal Number or any combination of the previous options into the search inputs.</p>
<p>The search results should yield registrations and renewals from the database and provide information including its description, publishers, and renewal history.</p>
<p>If this work has been found to be out of copyright, then it is able to be distributed freely online.</p>
<br>
<h3>How to determine if a book is in the public domain:</h3>
<li>Published before 1923: automatically in public domain.</li>
<li>Published from 1923-1963: In public domain if copyright hasn’t been renewed.</li>
<li>Published from 1964-1977: public domain after 28 years with additional 67 year automatic extension.</li>
<li>Published from 1978-present: in public domain for life of author plus additional 70 years.</li>
<li>Special circumstances: Created pre 1978 but not published: in public domain for life of author plus additional 70 years OR until 2003, whichever is greater.</li>
</div>
</div>
{% endblock %}
53 changes: 0 additions & 53 deletions cce_search/templates/results.html

This file was deleted.

7 changes: 4 additions & 3 deletions cce_search/templates/search/cceid.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ <h2>{% block title %}Entry {{ result["uuid"] }}{% endblock %}</h2>
{% endblock %}

{% block content %}
<div class="results">
{% if result["type"] %}
{% include "search/new_renewal.html" %}

{% include "search/new_renewal.html" %}
{% else %}
<div class="results">
{% include "search/new_registration.html" %}
</div>
{% endif %}
</div>
{% endblock %}

8 changes: 6 additions & 2 deletions cce_search/templates/search/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
{% if results %}
{% include "search/paging.html" %}
{% for result in results %}
<div class = "results">
<!-- {% include "search/render_registration.html" %} -->
<div class="results">
{% if result['type'] %}
{% include "search/new_renewal.html" %}
{% else %}
{% include "search/new_registration.html" %}
{% endif %}
</div>
{% endfor %}
{% include "search/paging.html" %}
{% else %}


Expand Down
5 changes: 1 addition & 4 deletions cce_search/templates/search/new_registration.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,14 @@ <h3>Registration {{ result['registrations'][0]['number'] }}</h3>
<tr>
<th scope="row">Renewals</th>
<td>
{% if result['is_post_1963'] %}
<em>Works published after 1963 do not require renewal and are in copyright</em>
{% else %}
{% if result['renewals'] %}
{% for renewal in result['renewals'] %}
{% include "search/render_child_renewal.html" %}
{% endfor %}
{% else %}
<em>No renewals found</em>
{% endif %}
{% endif %}

{% if result['is_foreign'] %}
<br>See note on <a href="/registration-classes#foreign">Foreign publications</a>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion cce_search/templates/search/paging.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<br>
{% else %}
{% if results %}
<div class="nav justify-content-end">Page 1 of 1</div>
<div class="nav float-right badge badge-primary">Page 1 of 1</div>
{% endif %}

{% endif %}
Expand Down
90 changes: 0 additions & 90 deletions cce_search/templates/search/render_registration.html

This file was deleted.

Loading