-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
55 lines (40 loc) · 1.6 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
from shutil import copyfile
from flask import (Flask, request, session, g, redirect, url_for, abort,
render_template, flash, current_app, send_from_directory)
from python import MarxBarchartCsv as mbc
app = Flask(__name__)
# By default: copy the contents of *words.cvs into words.csv
# Maybe do this differently with callbacks/ajax?
copyfile('./data/*words.csv', './data/words.csv')
# TODO index here the actual words in the /data folder
# perhaps don't need to index, can just check if it exists on the go
# current strategy: just generate a csv and place it in data/words.csv
@app.route("/", methods=['POST', 'GET'])
def home():
if request.method == 'POST':
# have js check if it's a good word anyways
word = request.form['input_word']
print(word)
if os.path.isfile('./data/' + word + '.csv'):
print('file exists')
else:
mbc.marx_concordance('./corpus/marx_kapital01_1867.txt',
word, out_directory='./data/')
# TODO: instead of reloading page, send a callback
# saying to load the file!
# this might just be a javascript thing though (ajax?)
return render_template('index.html')
else:
return render_template('index.html')
@app.route("/css/<path:path>")
def send_css(path):
return send_from_directory('css', path)
@app.route("/js/<path:path>")
def send_js(path):
return send_from_directory('js', path)
@app.route("/data/<path:path>")
def send_data(path):
return send_from_directory('data', path)
if __name__ == '__main__':
app.run()