2020-07-04 07:38:38 +00:00
|
|
|
# ----------------------------------------------- #
|
|
|
|
# Plugin Name : TradingView-Webhook-Bot #
|
2021-03-14 08:24:07 +00:00
|
|
|
# Author Name : fabston #
|
2020-07-04 07:38:38 +00:00
|
|
|
# File Name : main.py #
|
|
|
|
# ----------------------------------------------- #
|
|
|
|
|
2020-07-11 15:52:48 +00:00
|
|
|
import config
|
2020-07-12 07:48:57 +00:00
|
|
|
import time
|
|
|
|
from flask import Flask, request
|
2020-12-19 14:15:46 +00:00
|
|
|
import json
|
2020-07-11 15:52:48 +00:00
|
|
|
from handler import *
|
2020-04-21 14:29:00 +00:00
|
|
|
|
|
|
|
app = Flask(__name__)
|
2020-07-12 07:48:57 +00:00
|
|
|
|
2021-02-02 09:43:10 +00:00
|
|
|
def get_timestamp():
|
|
|
|
timestamp = time.strftime("%Y-%m-%d %X")
|
|
|
|
return timestamp
|
|
|
|
|
2020-12-19 14:15:46 +00:00
|
|
|
@app.route('/webhook', methods=['POST'])
|
2020-04-21 14:29:00 +00:00
|
|
|
def webhook():
|
2020-07-12 07:48:57 +00:00
|
|
|
try:
|
|
|
|
if request.method == 'POST':
|
2020-12-19 14:15:46 +00:00
|
|
|
data = request.get_json()
|
|
|
|
key = data['key']
|
|
|
|
if key == config.sec_key:
|
2021-02-02 09:43:10 +00:00
|
|
|
print(get_timestamp(), 'Alert Received & Sent!')
|
2020-12-19 14:15:46 +00:00
|
|
|
send_alert(data)
|
|
|
|
return 'Sent alert', 200
|
|
|
|
|
2020-07-12 07:48:57 +00:00
|
|
|
else:
|
2021-02-02 09:43:10 +00:00
|
|
|
print('[X]', get_timestamp(), 'Alert Received & Refused! (Wrong Key)')
|
2020-07-12 07:48:57 +00:00
|
|
|
return 'Refused alert', 400
|
2020-12-19 14:15:46 +00:00
|
|
|
|
2020-07-12 07:48:57 +00:00
|
|
|
except Exception as e:
|
2021-02-02 09:43:10 +00:00
|
|
|
print('[X]', get_timestamp(), 'Error:\n>', e)
|
2020-07-12 07:48:57 +00:00
|
|
|
return 'Error', 400
|
2020-04-21 14:29:00 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
from waitress import serve
|
|
|
|
serve(app, host='0.0.0.0', port=80)
|