initial commit

This commit is contained in:
raspbeguy 2017-06-06 11:52:29 +02:00
commit 84fa5253e8
2 changed files with 29 additions and 0 deletions

10
README.md Normal file
View File

@ -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/
```

19
app.py Executable file
View File

@ -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)