Merge branch 'master' of ssh://kawomi.com/var/local/git/deadswitch into master
# Conflicts: # api1.py
This commit is contained in:
22
api1.py
22
api1.py
@@ -1,6 +1,6 @@
|
|||||||
import flask
|
import flask
|
||||||
import sys
|
import sys
|
||||||
from flask import request, jsonify, g
|
from flask import request, jsonify, g, make_response
|
||||||
from flask_apscheduler import APScheduler
|
from flask_apscheduler import APScheduler
|
||||||
from datetime import datetime,timedelta,timezone
|
from datetime import datetime,timedelta,timezone
|
||||||
import sqlite3
|
import sqlite3
|
||||||
@@ -69,7 +69,11 @@ def sendMail(topic,toAddr):
|
|||||||
server=smtplib.SMTP("localhost", port)
|
server=smtplib.SMTP("localhost", port)
|
||||||
sender_email = "deadswitch@kawomi.com"
|
sender_email = "deadswitch@kawomi.com"
|
||||||
receiver_email = toAddr
|
receiver_email = toAddr
|
||||||
message = f"""Subject: deadSwitch not pushed on topic {topic}\n\nNotification of deadSwitch not pushed on topic {topic}."""
|
message = f"""Subject: deadSwitch not pushed on topic {topic}\n\nNotification of deadSwitch not pushed on topic {topic}.
|
||||||
|
|
||||||
|
https://deadswitch.kawomi.com/api/v1?topic={topic}
|
||||||
|
|
||||||
|
"""
|
||||||
sendSelfTelegram(message)
|
sendSelfTelegram(message)
|
||||||
server.sendmail(sender_email, receiver_email, message)
|
server.sendmail(sender_email, receiver_email, message)
|
||||||
|
|
||||||
@@ -122,6 +126,14 @@ if __name__ == '__main__':
|
|||||||
</ul>"""
|
</ul>"""
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/api/v1', methods=['OPTIONS'])
|
||||||
|
def api_returnOptions():
|
||||||
|
response = make_response()
|
||||||
|
response.headers.add("Access-Control-Allow-Origin", "*")
|
||||||
|
response.headers.add('Access-Control-Allow-Headers', "*")
|
||||||
|
response.headers.add('Access-Control-Allow-Methods', "*")
|
||||||
|
return response
|
||||||
|
|
||||||
@app.route('/api/v1', methods=['GET'])
|
@app.route('/api/v1', methods=['GET'])
|
||||||
def api_getByTopic():
|
def api_getByTopic():
|
||||||
if 'topic' in request.args:
|
if 'topic' in request.args:
|
||||||
@@ -135,7 +147,7 @@ if __name__ == '__main__':
|
|||||||
if theRow is None:
|
if theRow is None:
|
||||||
return jsonify({'success':False, 'error':f"No entry found for topic _{topic}_"})
|
return jsonify({'success':False, 'error':f"No entry found for topic _{topic}_"})
|
||||||
|
|
||||||
return jsonify({'success':True, 'topic':topic, 'active':bool(theRow[0]), 'expiry':theRow[1].strftime("%Y-%m-%d %H:%M:%S"), 'lastSeen':theRow[5].strftime("%Y-%m-%d %H:%M:%S"),'isExpired':bool(theRow[4]),'email':theRow[2], 'isNotified':bool(theRow[3])})
|
return _corsify_actual_response(jsonify({'success':True, 'topic':topic, 'active':bool(theRow[0]), 'expiry':theRow[1].strftime("%Y-%m-%d %H:%M:%S"), 'lastSeen':theRow[5].strftime("%Y-%m-%d %H:%M:%S"),'isExpired':bool(theRow[4]),'email':theRow[2], 'isNotified':bool(theRow[3])}))
|
||||||
|
|
||||||
@app.route('/api/v1', methods=['PUT','POST'])
|
@app.route('/api/v1', methods=['PUT','POST'])
|
||||||
def api_setRecord():
|
def api_setRecord():
|
||||||
@@ -166,4 +178,8 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
return jsonify({'success':True, 'expiry':expiryDateTime.strftime("%Y-%m-%d %H:%M:%S"), 'email':email})
|
return jsonify({'success':True, 'expiry':expiryDateTime.strftime("%Y-%m-%d %H:%M:%S"), 'email':email})
|
||||||
|
|
||||||
|
def _corsify_actual_response(response):
|
||||||
|
response.headers.add("Access-Control-Allow-Origin", "*")
|
||||||
|
return response
|
||||||
|
|
||||||
app.run(use_reloader=False,port=5123)
|
app.run(use_reloader=False,port=5123)
|
||||||
|
|||||||
Reference in New Issue
Block a user