-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.py
More file actions
66 lines (50 loc) · 1.9 KB
/
main.py
File metadata and controls
66 lines (50 loc) · 1.9 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# ------------------------------------------------------------------- #
# Plugin Name : TradingView-Webhook-Alert-Telegram-SnapShot #
# Author Name : rasoul707 #
# File Name : main.py #
# ------------------------------------------------------------------- #
import json
import time
from flask import Flask, request
import requests
import config
from helper import *
app = Flask(__name__)
def get_timestamp():
timestamp = time.strftime("%Y-%m-%d %X")
return timestamp
@app.route("/wh", methods=["POST"])
def webhook():
try:
if request.method == "POST":
data = request.get_json()
key = request.args.get('key')
if key in config.keys:
print(get_timestamp(), "New Alert Received & Prepare To Send!")
if sendAlert(data, key) == 'err':
return "Failed send", 400
return "Sent alert", 200
else:
print("[X]", get_timestamp(),
"New Alert Received & Refused! [Key Not Found]")
return "Refused alert", 400
except Exception as e:
print("[X]", get_timestamp(), "Error:\n>", e)
return "Error", 400
if __name__ == "__main__":
from waitress import serve
start = requests.get(
'http://localhost:7007/start?username='+config.username+'&password='+config.password)
data = start.json()
ok = data["ok"]
status = data["status"]
username = data["username"]
password = data["password"]
useragent = data["useragent"]
title = 'LoginFailed'
if ok:
title = 'LoginSuccess'
sen2Admin(
'<b>'+title+':</b> '+status+'\n<b>Username:</b> '+username+'\n<b>Password:</b> '+password+'\n<b>Useragent:</b> '+useragent)
print(get_timestamp(), title)
serve(app, host="0.0.0.0", port=80)