TradingView-Webhook-Bot/main.py

47 wiersze
1.2 KiB
Python
Czysty Zwykły widok Historia

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 #
# ----------------------------------------------- #
2021-06-22 12:34:31 +00:00
import json
import time
2021-06-22 12:34:31 +00:00
from flask import Flask, request
2021-06-22 12:34:31 +00:00
import config
2020-07-11 15:52:48 +00:00
from handler import *
2020-04-21 14:29:00 +00:00
app = Flask(__name__)
2021-03-27 07:20:00 +00:00
def get_timestamp():
timestamp = time.strftime("%Y-%m-%d %X")
return timestamp
2021-03-27 07:20:00 +00:00
2021-06-22 12:34:31 +00:00
@app.route("/webhook", methods=["POST"])
2020-04-21 14:29:00 +00:00
def webhook():
try:
2021-06-22 12:34:31 +00:00
if request.method == "POST":
data = request.get_json()
2021-06-22 12:34:31 +00:00
key = data["key"]
if key == config.sec_key:
2021-06-22 12:34:31 +00:00
print(get_timestamp(), "Alert Received & Sent!")
send_alert(data)
2021-06-22 12:34:31 +00:00
return "Sent alert", 200
else:
2021-06-22 12:34:31 +00:00
print("[X]", get_timestamp(), "Alert Received & Refused! (Wrong Key)")
return "Refused alert", 400
2021-03-27 07:20:00 +00:00
except Exception as e:
2021-06-22 12:34:31 +00:00
print("[X]", get_timestamp(), "Error:\n>", e)
return "Error", 400
2020-04-21 14:29:00 +00:00
2021-03-27 07:20:00 +00:00
2021-06-22 12:34:31 +00:00
if __name__ == "__main__":
2020-04-21 14:29:00 +00:00
from waitress import serve
2021-03-27 07:20:00 +00:00
2021-06-22 12:34:31 +00:00
serve(app, host="0.0.0.0", port=80)