-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
46 lines (36 loc) · 1.21 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# ----------------------------------------------- #
# Plugin Name : TradingView-Webhook-Bot #
# Author Name : fabston #
# File Name : main.py #
# ----------------------------------------------- #
import json
import os
import time
from flask import Flask, request
import logging
import config
from handler import *
logging.basicConfig(level=logging.INFO)
app = Flask(__name__)
def get_timestamp():
timestamp = time.strftime("%Y-%m-%d %X")
return timestamp
@app.route("/webhook", methods=["POST"])
def webhook():
try:
if request.method == "POST":
data = request.get_json()
key = data["key"]
if key == config.sec_key:
logging.info("Alert Received & Sent!")
send_alert(data)
return "Sent alert", 200
else:
logging.error('Alert Received & Refused! (Wrong Key)')
return "Refused alert", 400
except Exception as e:
logging.error("[X]", get_timestamp(), "Error:\n>", e)
return "Error", 400
if __name__ == "__main__":
from waitress import serve
serve(app, host='0.0.0.0', port=os.getenv("PORT", 80))