Skip to content
Snippets Groups Projects
Commit f1aa74ae authored by felixwelter's avatar felixwelter
Browse files

Reformat and remove comments

parent ba1b257a
No related branches found
No related tags found
No related merge requests found
import os
import sys
from pathlib import Path
import pdfplumber
from flask import Flask, render_template, request, redirect, send_file
from werkzeug.utils import secure_filename
from search_index import BasicSearchIndex
from title_focus_search_index import TitleFocusSearchIndex
import os
app = Flask(__name__)
......@@ -15,6 +15,7 @@ IMAGE_DIR = "img_cache"
Index = TitleFocusSearchIndex
@app.route('/')
def index():
ll = os.listdir(SLIDE_DIR)
......@@ -27,11 +28,8 @@ def allowed_file(filename):
@app.route('/upload', methods=['POST'])
def upload():
# check if the post request has the file part
if 'file' in request.files:
file = request.files['file']
# if user does not select file, browser also
# submit an empty part without filename
if file.filename != '':
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
......@@ -48,21 +46,19 @@ def upload():
del index
return redirect('/')
@app.route("/search")
def query():
try:
index = Index()
query = request.args.get("term")
result = index.search(query)
#pdf = pdfplumber.open(result["path"])
#page = pdf.pages[result["page"]]
img_name = result["path"][7:] + "_" + str(result["page"]) + ".jpg"
#img_path = os.path.join(IMAGE_DIR, img_name)
#page.to_image().save(img_path)
return "slide/" + img_name
except:
return str(sys.exc_info()[0]).replace("<", "-").replace(">", "-")
@app.route("/slide/<img_name>")
def slide(img_name):
path = os.path.join(IMAGE_DIR, img_name)
......
......@@ -8,6 +8,7 @@ from whoosh.qparser import QueryParser, OrGroup
class BasicSearchIndex:
"""Expose relevant functions of Whoosh using a simple interface"""
def __init__(self, index_dir="index"):
self.schema = Schema(path=ID(stored=True), page=NUMERIC(stored=True), content=TEXT(stored=True))
try:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment