Browse Source

refactoring

master
wes 8 years ago
parent
commit
be93c967c6
  1. 2
      src/search.py
  2. 22
      src/website.py

2
src/search.py

@ -161,7 +161,7 @@ def filterSections(secs):
return filtered return filtered
return False return False
def searchTerms(terms): def search_courses(terms):
""" """
Run a search for courses Run a search for courses
""" """

22
src/website.py

@ -1,25 +1,19 @@
#! /usr/bin/python3 #! /usr/bin/python3
from functools import partial 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 import Blueprint, abort, Flask, render_template, flash, request, send_from_directory, jsonify
from flask_bootstrap import Bootstrap from flask_bootstrap import Bootstrap
from flask_appconfig import AppConfig 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 openlibrary import bookUrls
from syslog import syslog
from archive import searchIA 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']) cache = MemcachedCache(['127.0.0.1:11211'])
import os
def predict(fieldtype, term): def predict(fieldtype, term):
print(fieldtype) print(fieldtype)
print(term) print(term)
@ -75,7 +69,7 @@ def ClassSearch(configfile=None):
for key, val in params.items(): for key, val in params.items():
if val in defaults: if val in defaults:
del params[key] del params[key]
return jsonify(searchTerms(params)) return jsonify(search_courses(params))
@blueprint.route("/resources", methods=("GET", "POST")) @blueprint.route("/resources", methods=("GET", "POST"))
def resources(): def resources():
@ -84,14 +78,14 @@ def ClassSearch(configfile=None):
try: try:
params = loads(unquote(dict(request.args.items())["data"])) params = loads(unquote(dict(request.args.items())["data"]))
except KeyError: except KeyError:
return jsonify("false") return jsonify(False)
print(params) print(params)
author = params["author"] author = params["author"]
title = params["title"] title = params["title"]
if ("No Textbooks" in title or if ("No Textbooks" in title or
"No Adoption" in title): "No Adoption" in title):
return jsonify("false") return jsonify(False)
# Cache the result of the open library search # Cache the result of the open library search
openlib = cacheit("openlib"+title+author, lambda : bookUrls(title, author)) openlib = cacheit("openlib"+title+author, lambda : bookUrls(title, author))
@ -103,7 +97,7 @@ def ClassSearch(configfile=None):
if not (any(openlib) or any(iarchive)): if not (any(openlib) or any(iarchive)):
# We literally could not find ANYTHING # We literally could not find ANYTHING
return jsonify("false") return jsonify(False)
return jsonify({ return jsonify({
"iarchive" : iarchive, "iarchive" : iarchive,

Loading…
Cancel
Save