TradingView-Webhook-Bot/main.py

36 wiersze
1.2 KiB
Python
Czysty Zwykły widok Historia

2020-07-04 07:38:38 +00:00
# ----------------------------------------------- #
# Plugin Name : TradingView-Webhook-Bot #
# Author Name : sixBit #
# File Name : main.py #
# ----------------------------------------------- #
2020-07-11 15:52:48 +00:00
import config
import time
from flask import Flask, request
2020-07-11 15:52:48 +00:00
from handler import *
2020-04-21 14:29:00 +00:00
timestamp = time.strftime("%Y-%m-%d %X")
2020-04-21 14:29:00 +00:00
app = Flask(__name__)
2020-04-21 14:29:00 +00:00
@app.route('/webhook', methods=['POST'])
def webhook():
try:
if request.method == 'POST':
data = request.get_data(as_text=True)
for whitelisted in config.whitelisted:
if whitelisted.lower() in data.lower():
print('[✓]', timestamp, 'Alert Received & Sent!\n>', data)
send_alert(data)
return 'Sent alert', 200
else:
print('[✗]', timestamp, 'Alert Received & Refused!\n>', data)
return 'Refused alert', 400
2020-04-21 14:29:00 +00:00
else:
return 'Refused alert', 400
except Exception as e:
print('[✘]', timestamp, 'Error:\n>', e)
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)