Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Combine two views for /webview/ into one #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 30 additions & 27 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,29 @@
game = Game(db=db)

# --------------------------------------------------------------- #
@app.route('/webview/', methods=['POST'])


@app.route('/webview/', methods=['GET', 'POST'])
def getProfile():
if request.method == 'GET':
id = request.args.get('id')
print("PROFILE ID", id)
user = usersdb.get(id)
bio = user.bio
interests = user.interests
level = user.level
level_str = u'\u2B50'

for i in range(level):
level_str = level_str + u'\u2B50'

if bio is None:
bio = ""
if interests is None:
interests = ""
return render_template('profile.html', id=id, bio=bio, interests=interests, level=level_str)

# On POST calls
try:
print("FORM SUBMITTED", dict(request.form))
bio = request.form['bio']
Expand All @@ -48,26 +69,8 @@ def getProfile():
user.liked = True
db.session.commit()
return render_template('result.html')
except Exception, e:
print("FORM ERROR", str(e))

@app.route('/webview/', methods=['GET'])
def render():
id = request.args.get('id')
print("PROFILE ID", id)
user = usersdb.get(id)
bio = user.bio
interests = user.interests
level = user.level
level_str = u'\u2B50'
for i in range(level):
level_str = level_str + u'\u2B50'

if bio is None:
bio = ""
if interests is None:
interests = ""
return render_template('profile.html', id=id, bio=bio, interests=interests, level=level_str)
except Exception as e:
print("FORM ERROR: ", str(e))


@app.route('/webhook/', methods=['GET', 'POST'])
Expand All @@ -86,8 +89,8 @@ def webhook():
try:
if sender != PAGE_ID and usersdb.hasDataOf(sender) is False:
usersdb.add(sender)
except Exception, e:
print("ERROR", str(e))
except Exception as e:
print("ERROR: ", str(e))


try:
Expand All @@ -105,8 +108,8 @@ def webhook():
continue
else:
print("NOT POSTBACK OR INTERRUPT")
except Exception, e:
print("POSTBACK/INTERRUPT ERROR", str(e))
except Exception as e:
print("POSTBACK/INTERRUPT ERROR: ", str(e))
db.session.rollback()
return ''

Expand Down Expand Up @@ -143,8 +146,8 @@ def webhook():
message = TextTemplate(text="Debug command executed")
send_message(message.get_message(), id=recipient)
continue
except Exception, e:
print("DEBUG ERROR", str(e))
except Exception as e:
print("DEBUG ERROR: ", str(e))

if 'quick_reply' in event['message'] and 'payload' in event['message']['quick_reply']:
quick_reply_payload = event['message']['quick_reply']['payload']
Expand Down