-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.py
97 lines (78 loc) · 2.68 KB
/
server.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from flask import Flask, request
from tradingview import tradingview
import json
#from threading import Thread
app = Flask(__name__)
@app.route('/validate/<username>', methods=['GET'])
def validate(username):
try:
print(username)
tv = tradingview()
response = tv.validate_username(username)
return json.dumps(response), 200, {'Content-Type': 'application/json; charset=utf-8'}
except Exception as e:
print("[X] Exception Occured : ", e)
failureResponse = {
'errorMessage':'Unknown Exception Occurred1'
}
return json.dumps(failureResponse), 500, {'Content-Type': 'application/json; charset=utf-8'}
@app.route('/check-access/<username>', methods=['POST'])
def check_access(username):
print(username)
try:
jsonPayload = request.json
print(jsonPayload)
pine_id = jsonPayload.get('pine_id')
print(jsonPayload)
print(pine_id)
tv = tradingview()
accessList = []
access = tv.get_access_details(username, pine_id)
accessList = accessList + [access]
return json.dumps(accessList), 200, {'Content-Type': 'application/json; charset=utf-8'}
except Exception as e:
print("[X] Exception Occured : ", e)
failureResponse = {
'errorMessage':'Unknown Exception Occurred'
}
return json.dumps(failureResponse), 500, {'Content-Type': 'application/json; charset=utf-8'}
@app.route('/access/<username>', methods=['POST', 'DELETE'])
def access(username):
print(username)
try:
jsonPayload = request.json
pine_id = jsonPayload.get('pine_id')
print(jsonPayload)
print(pine_id)
tv = tradingview()
accessList = []
#for pine_id in pine_ids:
access = tv.get_access_details(username, pine_id)
accessList = accessList + [access]
print("+++++++++",accessList)
if request.method == 'POST':
duration = jsonPayload.get('duration')
dNumber = int(duration[:-1])
dType = duration[-1:]
for access in accessList:
tv.add_access(access, dType, dNumber)
if request.method == 'DELETE':
for access in accessList:
tv.remove_access(access)
return json.dumps(accessList), 200, {'Content-Type': 'application/json; charset=utf-8'}
except Exception as e:
print("[X] Exception Occured : ", e)
failureResponse = {
'errorMessage':'Unknown Exception Occurred'
}
return json.dumps(failureResponse), 500, {'Content-Type': 'application/json; charset=utf-8'}
@app.route('/')
def main():
return 'Your bot is alive!'
# def run():
# app.run(host='0.0.0.0', port=5000)
# def start_server_async():
# server = Thread(target=run)
# server.start()
def start_server():
app.run(host='0.0.0.0', port=5000)