initial commit
This commit is contained in:
commit
84fa5253e8
|
@ -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/
|
||||||
|
```
|
|
@ -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)
|
Loading…
Reference in New Issue