Created
May 23, 2017 20:58
-
-
Save sagnew/95da136c22ec2ac702eade9b2badbbd3 to your computer and use it in GitHub Desktop.
Python debugging code challenge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from flask import Flask, request | |
from twilio import twiml | |
app = Flask(__name__) | |
@app.route('/sms', methods=['POST']): # This decorator has no function. There should be a function def on the next line. | |
message_body = request.form['Body'] | |
response_message = ('Thanks for playing :) Hit up @Sagnewshreds ' | |
'on Twitter for questions!') | |
error_message = ('Please enter a 4 digit hex address followed by a ' | |
'2 digit hex value to write to that address.\n\n' | |
'Example: "0779: 1f"') | |
message_list = message_body.split(' ') | |
hex_pattern = re.compile('^[0-9a-F]+$') # This regex is straight up invalid. | |
if len(message_list) == 2: | |
address, value = message_list | |
if hex_pattern.match(address) and hex_pattern.match(value): | |
with f as open('address.txt', 'w'): # F and the open() call need to switch places. | |
f.write(address) | |
with open('value.txt') as f: # value.txt should be opened with the 'w' flag as above. | |
f.write(value) | |
else: | |
response_message = error_message | |
else: | |
response_message = error_message | |
resp = twiml.Response() | |
resp.message(response_message) | |
return str(resp) | |
if __name__ == __main__: # '__main__' should be a string. | |
app.run(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment