Skip to content

Commit

Permalink
Add Gateway function
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorsantanna2 committed Mar 23, 2024
1 parent 40f3de4 commit ded0e89
Show file tree
Hide file tree
Showing 2 changed files with 194 additions and 1 deletion.
174 changes: 174 additions & 0 deletions handler/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,180 @@ def getInfo(bs, title="title"):
return ret


def getGateway(bshealth, bsscore, title):
status = str(bshealth['status'])
uptime = str(bshealth['uptime'])
most_recent = str(bsscore['most_recent'])
key = ['title', 'status', 'uptime', 'most_recent']
res = []
res.insert(0, title)
res.insert(1, status)
res.insert(2, uptime)
res.insert(3, most_recent)
ret = dict(zip(key, res))
return ret

@app.route("/gateway1")
def gateway1():
title = 'Gateway 1 - Australia'
try:
health = urlopen("http://gateway1.tupinymquim.com:8080/api/v1/health", timeout=0.4)
score = urlopen("https://validator.nymtech.net/api/v1/status/gateway/5SHU62fW1L4xMBEXnfxU9Zz49U9tjQUiDmqEcggUYMNb/report", timeout=0.4)
except:
key = ['title', 'status', 'uptime', 'most_recent']
res = []
res.insert(0, title)
res.insert(1, "down")
res.insert(2, "0")
res.insert(3, "0")
ret = dict(zip(key, res))
return ret
bshealth = json.loads(str(BeautifulSoup(health, 'html.parser')))
bsscore = json.loads(str(BeautifulSoup(score, 'html.parser')))
res = getGateway(bshealth, bsscore, title)
return res

@app.route("/gateway2")
def gateway2():
title = 'Gateway 2 - Espanha'
try:
health = urlopen("http://gateway2.tupinymquim.com:8080/api/v1/health", timeout=0.4)
score = urlopen("https://validator.nymtech.net/api/v1/status/gateway/AG1jucgspds2xXJAftZHr7tqf3haPNjWLyRsn9NzfWje/report", timeout=0.4)
except:
key = ['title', 'status', 'uptime', 'most_recent']
res = []
res.insert(0, title)
res.insert(1, "down")
res.insert(2, "0")
res.insert(3, "0")
ret = dict(zip(key, res))
return ret
bshealth = json.loads(str(BeautifulSoup(health, 'html.parser')))
bsscore = json.loads(str(BeautifulSoup(score, 'html.parser')))
res = getGateway(bshealth, bsscore, title)
return res


@app.route("/gateway3")
def gateway3():
title = 'Gateway 3 - Brasil'
try:
health = urlopen("http://gateway3.tupinymquim.com:8080/api/v1/health", timeout=0.4)
score = urlopen("https://validator.nymtech.net/api/v1/status/gateway/49PcvZKw3UHa3w88xCKKCshFWz139mPMx7ZEX2Wg9jqk/report", timeout=0.4)
except:
key = ['title', 'status', 'uptime', 'most_recent']
res = []
res.insert(0, title)
res.insert(1, "down")
res.insert(2, "0")
res.insert(3, "0")
ret = dict(zip(key, res))
return ret
bshealth = json.loads(str(BeautifulSoup(health, 'html.parser')))
bsscore = json.loads(str(BeautifulSoup(score, 'html.parser')))
res = getGateway(bshealth, bsscore, title)
return res

@app.route("/gateway4")
def gateway4():
title = 'Gateway 4 - Itália'
try:
health = urlopen("http://gateway4.tupinymquim.com:8080/api/v1/health", timeout=0.4)
score = urlopen("https://validator.nymtech.net/api/v1/status/gateway/DgD7K1RHn7kMPC3ibg6HkJFkDqaFstxpEFHgronRdCqj/report", timeout=0.4)
except:
key = ['title', 'status', 'uptime', 'most_recent']
res = []
res.insert(0, title)
res.insert(1, "down")
res.insert(2, "0")
res.insert(3, "0")
ret = dict(zip(key, res))
return ret
bshealth = json.loads(str(BeautifulSoup(health, 'html.parser')))
bsscore = json.loads(str(BeautifulSoup(score, 'html.parser')))
res = getGateway(bshealth, bsscore, title)
return res

@app.route("/gateway5")
def gateway5():
title = 'Gateway 5 - Noruega'
try:
health = urlopen("http://gateway5.tupinymquim.com:8080/api/v1/health", timeout=0.4)
score = urlopen("https://validator.nymtech.net/api/v1/status/gateway/8R9CjJsfWbAmisHcarJYLrvTdkW1D4CLyy3iAY89j5QF/report", timeout=0.4)
except:
key = ['title', 'status', 'uptime', 'most_recent']
res = []
res.insert(0, title)
res.insert(1, "down")
res.insert(2, "0")
res.insert(3, "0")
ret = dict(zip(key, res))
return ret
bshealth = json.loads(str(BeautifulSoup(health, 'html.parser')))
bsscore = json.loads(str(BeautifulSoup(score, 'html.parser')))
res = getGateway(bshealth, bsscore, title)
return res

@app.route("/gateway6")
def gateway6():
title = 'Gateway 6 - Singapura'
try:
health = urlopen("http://gateway6.tupinymquim.com:8080/api/v1/health", timeout=0.4)
score = urlopen("https://validator.nymtech.net/api/v1/status/gateway/Eb15FTXQgnenwLmqdfCQNj6PmKjMszrmHhtXqKKRafMW/report", timeout=0.4)
except:
key = ['title', 'status', 'uptime', 'most_recent']
res = []
res.insert(0, title)
res.insert(1, "down")
res.insert(2, "0")
res.insert(3, "0")
ret = dict(zip(key, res))
return ret
bshealth = json.loads(str(BeautifulSoup(health, 'html.parser')))
bsscore = json.loads(str(BeautifulSoup(score, 'html.parser')))
res = getGateway(bshealth, bsscore, title)
return res

@app.route("/gateway7")
def gateway7():
title = 'Gateway 7 - Bélgica'
try:
health = urlopen("http://gateway7.tupinymquim.com:8080/api/v1/health", timeout=0.4)
score = urlopen("https://validator.nymtech.net/api/v1/status/gateway/5P8MmJTdmoS4rhV8VHArABkyPE3M9RMrZsiX3qYkJ6u/report", timeout=0.4)
except:
key = ['title', 'status', 'uptime', 'most_recent']
res = []
res.insert(0, title)
res.insert(1, "down")
res.insert(2, "0")
res.insert(3, "0")
ret = dict(zip(key, res))
return ret
bshealth = json.loads(str(BeautifulSoup(health, 'html.parser')))
bsscore = json.loads(str(BeautifulSoup(score, 'html.parser')))
res = getGateway(bshealth, bsscore, title)
return res

@app.route("/gateway8")
def gateway8():
title = 'Gateway 8 - África do Sul'
try:
health = urlopen("http://gateway8.tupinymquim.com:8080/api/v1/health", timeout=0.4)
score = urlopen("https://validator.nymtech.net/api/v1/status/gateway/FGQXnYX5JFEA71ZUUNU2JkrLYpbjraYthQvnTgVKvXVX/report", timeout=0.4)
except:
key = ['title', 'status', 'uptime', 'most_recent']
res = []
res.insert(0, title)
res.insert(1, "down")
res.insert(2, "0")
res.insert(3, "0")
ret = dict(zip(key, res))
return ret
bshealth = json.loads(str(BeautifulSoup(health, 'html.parser')))
bsscore = json.loads(str(BeautifulSoup(score, 'html.parser')))
res = getGateway(bshealth, bsscore, title)
return res

@app.route("/tupi1")
def tupi1():
info = urlopen("https://explorer.nymtech.net/api/v1/mix-node/1356")
Expand Down
21 changes: 20 additions & 1 deletion telegram/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,31 @@ def list_nodes(message):
try:
res = requests.get("http://localhost:5000/tupi" + message.text[7])
temp = res.json()
print(temp)
text = temp.get("title") + "\n" + "Avg Score: " + temp.get("avg_uptime") + "\nRouting Score: " + temp.get("node_performance") + "%\nTotal Stake: " + temp.get("total_stake") + "\nLocation: " + temp.get("location")
except:
text = "invalid arguments"
bot.reply_to(message, f"{text}")

@bot.message_handler(commands=['gateways'])
def list_gateways(message):
i = 0
text = ""
if (len(message.text) < 10):
while (i < 8):
res = requests.get("http://localhost:5000/gateway" + str(i + 1))
temp = res.json()
print(temp)
text = text + temp.get("title") + "\n" + "Status: " + temp.get("status") + "\n" + "Uptime: " + temp.get("uptime") + "\nPerformance: " + temp.get("most_recent") + "%\n"
i = i + 1
else:
try:
res = requests.get("http://localhost:5000/gateway" + message.text[10])
temp = res.json()
text = text + temp.get("title") + "\n" + "Status: " + temp.get("status") + "\n" + "Uptime: " + temp.get("uptime") + "\nPerformance: " + temp.get("most_recent") + "%\n"
except:
text = "invalid arguments"
bot.reply_to(message, f"{text}")

@bot.message_handler(chat_id=[2092310259], commands=['apagar'])
def delete_list(message):
eraselist()
Expand Down

0 comments on commit ded0e89

Please sign in to comment.