diff --git a/api.py b/api.py index 3fc4902..d8c9254 100644 --- a/api.py +++ b/api.py @@ -43,6 +43,7 @@ def __init__(self, facebook_auth_filename=SECRETS_FILENAME): self.authed = False self.profiles = None self.friends = set() + def _load_fb_auth(self): diff --git a/app.py b/app.py index 4e31ba5..be48a6d 100644 --- a/app.py +++ b/app.py @@ -1,18 +1,48 @@ - - -from flask import Flask, render_template +from flask import Flask, render_template, request, g import api app = Flask('tinder-detective') -stalker = api.NSASimulator() - @app.route('/') def index(): - profiles = stalker.get_profiles() - return render_template("main.html", profiles=profiles) + + stalker = getattr(g, 'stalker', None) + + if stalker is None: + try: + stalker = api.NSASimulator() + except api.AuthenticationError: + return render_template("create_secrets.html") + + g.stalker = stalker + + error = None + profiles = None + try: + profiles = stalker.get_profiles() + except api.AuthenticationError: + print("Auth error") + error = "There was a problem with authentication" + return render_template("profiles.html", profiles=profiles, error=error) + + +@app.route('/create_secret', methods=['POST']) +def create_secret(): + data = request.form + + user_id = data['user_id'] + user_secret = data['user_secret'] + + with open('SECRETS.json', 'w') as f: + f.write("{\n") + f.write(" \"facebook_id\": \"" + user_id + "\",\n") + f.write(" \"facebook_token\": \"" + user_secret + "\"") + f.write("\n") + f.write("}") + + return "Successfully wrote to file, please reload the main page" if __name__ == '__main__': - app.run(debug=True) + app.run(debug=False, port=8080) diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..2c1eb62 --- /dev/null +++ b/templates/base.html @@ -0,0 +1,27 @@ + + + + + + + + + + +
+
+

Tinder detective I guess

+ +

"It's important to note Tinder's not a secret considering 70% of users download Tinder because their friends recommend it."

+
+
+ + {% block content %} + + {% endblock %} + + + + + + diff --git a/templates/create_secrets.html b/templates/create_secrets.html new file mode 100644 index 0000000..c437662 --- /dev/null +++ b/templates/create_secrets.html @@ -0,0 +1,23 @@ +{% extends 'base.html' %} + +{% block content %} + +
+

Please create the SECRETS.json file

+ +
+ + Facebook user id:
+ + +

+ Facebook Tinder secret:
+ +
+ + + +
+ +
+{% endblock %} diff --git a/templates/main.html b/templates/profiles.html similarity index 71% rename from templates/main.html rename to templates/profiles.html index 929545a..3799529 100644 --- a/templates/main.html +++ b/templates/profiles.html @@ -1,22 +1,15 @@ - - - - +{% extends 'base.html' %} - +{% block content %} +
- - - -
-
-

Tinder detective I guess

+ {% if error %} + +

{{ error }}

-

"It's important to note Tinder's not a secret considering 70% of users download Tinder because their friends recommend it."

-
-
+ {% endif %} -
+ {% if profiles %} {% for profile in profiles %}
@@ -57,10 +50,8 @@

{{ profile.name }}

{% endfor %} + {% endif %}
+ {% endblock %} - - - -