Created
October 19, 2012 14:32
-
-
Save pingswept/3918516 to your computer and use it in GitHub Desktop.
light blade code test
This file contains 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
from flask import Flask, render_template, request | |
public = Flask(__name__) | |
@public.route('/sms', methods=['POST']) | |
def parse_sms(): | |
import pytronics | |
sender = request.form['From'] | |
message = request.form['Body'] | |
print 'SMS received from %s: %s' % (sender, message) | |
command = translate_to_iplayer(message) | |
if command != 'Show not found': | |
pytronics.send_serial(command, 9600) | |
print 'Command %s sent out serial port' % (command) | |
else: | |
print command | |
def translate_to_iplayer(msg): | |
d = { | |
'off' : 'X0100', | |
'darker' : 'X03C0', # darker by 64 out of 255 | |
'brighter' : 'X0340', # brighter by 64 out of 255 | |
'cylon' : 'X0401', | |
'scanner' : 'X0402', | |
'red' : 'X0403', | |
'green' : 'X0404', | |
'blue' : 'X0405' } | |
try: | |
command = d[msg[:10].lower()] # Cut the message off at 10 characters for security | |
except KeyError: | |
command = 'Show not found' | |
return command | |
if __name__ == "__main__": | |
public.run(host='127.0.0.1:5000', debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment