forked from unl1k3ly/AnchorHODL
-
Notifications
You must be signed in to change notification settings - Fork 2
/
webview.py
92 lines (72 loc) · 3.02 KB
/
webview.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
from flask import Flask
import os
import subprocess
from flask import Response, render_template
from apscheduler.schedulers.background import BackgroundScheduler
from anchor_loan_repay import keep_loan_safe
from terraswap_swap_watch import run_terra_swap_price_watcher, get_luna_price_prices
app = Flask(__name__)
scheduler = BackgroundScheduler(daemon=True)
scheduler .add_job(keep_loan_safe, 'interval', seconds=30)
# scheduler .add_job(process_notifications, 'interval', minutes=3)
scheduler .start()
@app.route('/')
def tail():
info_log = []
repay_log = []
apscheduler_log = []
page_tile = 'null'
if os.path.exists('./logs/info.log'):
arguments = ['tail', '-n', '10', './logs/info.log']
process = subprocess.Popen(arguments, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in iter(process.stdout.readline, b''):
l = line.decode('utf-8')
line = l.strip()
info_log.append(line)
# get the last "left to trigger"
try:
if 'Left until trigger: ' in info_log[-1]:
page_title = info_log[-1].split()[5].strip(',')
elif 'REPAYING' in info_log[-1]:
page_title = 'REPAYING ...'
else:
page_title = '...'
except IndexError:
page_title = '...'
pass
if os.path.exists('./logs/repay.log'):
arguments = ['tail', '-n', '5', './logs/repay.log']
process = subprocess.Popen(arguments, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in iter(process.stdout.readline, b''):
l = line.decode('utf-8')
line = l.strip()
try:
url = line.split()[-1]
hlink = url
line = line.split(' TX')[0]
except Exception as err:
hlink = 'err'
line = 'err'
url = 'err'
pass
repay_log.append({'line': line, 'hlink': hlink})
if os.path.exists('./logs/apscheduler.log'):
arguments = ['tail', '-n', '5', './logs/apscheduler.log']
process = subprocess.Popen(arguments, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in iter(process.stdout.readline, b''):
l = line.decode('utf-8')
line = l.strip()
apscheduler_log.append(line)
else:
return "Could not read info.log"
terraswap_prices = run_terra_swap_price_watcher()
luna_prices = get_luna_price_prices()
# Reverse all lists ...
info_log.reverse()
repay_log.reverse()
apscheduler_log.reverse()
return render_template('index.html', title=page_title, buffer_list=info_log, repay_list=repay_log,
terraswap_prices=terraswap_prices, luna_price=luna_prices, apscheduler_list=apscheduler_log)
# return Response(json.dumps(buffer), mimetype='application/json')
if __name__ == '__main__':
app.run()