-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
81 lines (55 loc) · 2.07 KB
/
app.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from flask import Flask, render_template, request, Response, make_response
from analysis.user_base import IDGenerator
from analysis.user_handling import UserCreator, UserHandler, UserPairHandler, all_matches
from config import PREVENT_SERVER_CRASH
app = Flask(__name__)
@app.route("/", methods=["GET"])
async def index() -> Response:
new_user_id = IDGenerator.unique_id()
resp = make_response(render_template("website.html", userID=new_user_id))
return resp
@app.route("/store-txy", methods=["POST"])
async def store_mouse_position() -> Response:
if PREVENT_SERVER_CRASH:
return safe_print_and_plot()
print_and_plot()
return Response(status=204)
@app.route("/users-correlated-to-me", methods=["GET"])
async def correlated_users() -> Response:
return Response(status=404)
def print_and_plot() -> None:
user = UserCreator(req=request).user()
user_handler = UserHandler(user=user)
user_handler.calc_and_store_metrics()
user_handler.insert_user()
user_handler.print_user()
UserPairHandler().insert_valid_user_pairs()
all_matches.print_user_pairs()
for user_pair in all_matches:
UserPairHandler().plot_and_save_user_pair(user_pair=user_pair)
def safe_print_and_plot() -> Response:
try:
print_and_plot()
except Exception as e:
print(e)
return Response(status=400)
return Response(status=204)
if __name__ == "__main__":
app.run(debug=True)
"""
HOW TO RUN IT
Run in terminal:
gunicorn -w 4 -b 0.0.0.0:65000 app:app
To run it normally with Tor and a normal browser you must:
a. port-forward port 65000 in your router (or any other port you aren't using)
b. find your IP
c. visit <your-IP>:65000
To test it locally using only a normal browser:
a. edit the config file to allow pair matching between non-Tor browsers
b. Open http://0.0.0.0:65000/ on two windows (not maximized)
c1. move mouse from one window into the other
c2. or alt-tab and move it
d. .. until matches are plotted.
Before re-running it, use:
killall gunicorn
"""