From 84fa5253e8c22d5571d7528189a4464ad5b9794d Mon Sep 17 00:00:00 2001 From: raspbeguy Date: Tue, 6 Jun 2017 11:52:29 +0200 Subject: [PATCH] initial commit --- README.md | 10 ++++++++++ app.py | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 README.md create mode 100755 app.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..7bb7ded --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# sendsms + +This is a very small web API to send SMS using SMSTools 3. +Just use json POST requests. + +Exemple with curl: + +``` +curl -i -H "Content-Type: application/json" -X POST -d '{"phone":"33612345678","text":"Do a barrel roll"}' http://localhost:5000/ +``` diff --git a/app.py b/app.py new file mode 100755 index 0000000..7a55781 --- /dev/null +++ b/app.py @@ -0,0 +1,19 @@ +#!/bin/env python +from flask import Flask, jsonify, request, abort +import subprocess + +app = Flask(__name__) + +@app.route('/', methods=['POST']) +def send_sms(): + if not request.json or not 'phone' in request.json or not 'text' in request.json: + abort(400) + p = subprocess.run(['/usr/bin/sendsms', request.json['phone'], request.json['text']]) + print(p.returncode) + if p.returncode != 0: + abort(400) + else: + return jsonify({'result': 'success'}), 201 + +if __name__ == '__main__': + app.run(debug=True)