From be93c967c671269a85ebda84d8ce7b5b8e75ab78 Mon Sep 17 00:00:00 2001 From: wes Date: Tue, 17 Jan 2017 18:38:28 -0500 Subject: [PATCH] refactoring --- src/search.py | 2 +- src/website.py | 22 ++++++++-------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/search.py b/src/search.py index e120008..59a06b0 100755 --- a/src/search.py +++ b/src/search.py @@ -161,7 +161,7 @@ def filterSections(secs): return filtered return False -def searchTerms(terms): +def search_courses(terms): """ Run a search for courses """ diff --git a/src/website.py b/src/website.py index 8be781a..7d3ebb9 100755 --- a/src/website.py +++ b/src/website.py @@ -1,25 +1,19 @@ #! /usr/bin/python3 from functools import partial +from urllib.parse import quote, unquote +from json import loads from flask import Blueprint, abort, Flask, render_template, flash, request, send_from_directory, jsonify from flask_bootstrap import Bootstrap from flask_appconfig import AppConfig +from werkzeug.contrib.cache import MemcachedCache -from search import searchTerms - +from search import search_courses from openlibrary import bookUrls - -from syslog import syslog - from archive import searchIA -from urllib.parse import quote, unquote -from json import loads -from werkzeug.contrib.cache import MemcachedCache cache = MemcachedCache(['127.0.0.1:11211']) -import os - def predict(fieldtype, term): print(fieldtype) print(term) @@ -75,7 +69,7 @@ def ClassSearch(configfile=None): for key, val in params.items(): if val in defaults: del params[key] - return jsonify(searchTerms(params)) + return jsonify(search_courses(params)) @blueprint.route("/resources", methods=("GET", "POST")) def resources(): @@ -84,14 +78,14 @@ def ClassSearch(configfile=None): try: params = loads(unquote(dict(request.args.items())["data"])) except KeyError: - return jsonify("false") + return jsonify(False) print(params) author = params["author"] title = params["title"] if ("No Textbooks" in title or "No Adoption" in title): - return jsonify("false") + return jsonify(False) # Cache the result of the open library search openlib = cacheit("openlib"+title+author, lambda : bookUrls(title, author)) @@ -103,7 +97,7 @@ def ClassSearch(configfile=None): if not (any(openlib) or any(iarchive)): # We literally could not find ANYTHING - return jsonify("false") + return jsonify(False) return jsonify({ "iarchive" : iarchive,