-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
53 lines (39 loc) · 1.38 KB
/
server.py
File metadata and controls
53 lines (39 loc) · 1.38 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
from flask import Flask, request
from threading import Thread
import json
import telegrambot # Pastikan modul telegrambot sudah diimpor atau didefinisikan
app = Flask('')
@app.route('/webhook', methods=['POST', 'GET'])
def get_webhook():
try:
jsonRequest = request.args.get("jsonRequest")
if request.method == 'POST':
payload = request.data
if jsonRequest == "true":
payload = json.loads(request.data)
payload = json.dumps(payload, indent=4)
else:
payload = request.data.decode('utf-8')
print("received data:\n", payload)
telegrambot.sendMessage(payload)
return 'success', 200
else:
print("Get request")
return 'success', 200
except Exception as e:
print("[X] Exception Occurred:", e)
return 'failure', 500
@app.route('/')
def main():
# Assuming tradingview.login() is meant to be a function call related to tradingview
# You can add your tradingview login logic here
return 'Your bot is alive!'
def run():
app.run(host='0.0.0.0', port=8080)
def start_server_async():
server_thread = Thread(target=run)
server_thread.start()
def start_server():
app.run(host='0.0.0.0', port=8080)
if __name__ == '__main__':
start_server()