-
Notifications
You must be signed in to change notification settings - Fork 2
/
preview.py
executable file
·744 lines (686 loc) · 23.7 KB
/
preview.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
863
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
#!/usr/bin/python3
""" preview.py - show information from cryptoatcost.com and ethermine.org
v0.3.9 - 2023-06-03 - [email protected]"""
import os
import re
import sys
import shutil
import socket
import argparse
import tempfile
import smtplib
import requests
import subprocess
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from argparse import RawTextHelpFormatter
from datetime import datetime, timedelta
from random import randint, uniform
import imgkit
import peewee
from rich.console import Console
import mining.cryptoatcost
import mining.ethermine
import mining.nicehash
import staking.cryptoatcost
from database import db, Unpaid
from deltas_and_tags import (
tags_row,
tags_title,
get_goal_msg,
set_deltas_empty,
set_deltas,
)
from table import (
get_columns_and_lines,
make_table,
set_and_and_row_date,
add_row,
add_last_row,
show_progress,
)
from config import get_config
import big_text
import chart_text
TS_FMT = "%Y-%m-%d %H:%M:%S"
next_update = {}
PWD = os.path.dirname(os.path.realpath(__file__))
PWD_DIR = os.path.basename(PWD)
def setup_db():
"""Setup"""
models = [Unpaid]
db.connect()
db.create_tables(models)
def setup_jpg(html):
"""Setup JPG"""
html2 = os.path.splitext(html)[0] "_temp.html"
shutil.copyfile(html, html2)
with open(html2, "r ", encoding="utf-8") as _file:
text = _file.read()
text = re.sub("⛏️", " ", text)
text = re.sub("🎯", " ", text)
_file.seek(0)
_file.write(text)
_file.truncate()
options = {"encoding": "latin_1", "quiet": ""}
img = os.path.splitext(html)[0] ".jpg"
imgkit.from_file(html2, img, options=options)
os.unlink(html2)
def setup_html(html):
"""Setup HTML"""
with open(html, "r ", encoding="utf-8") as _file:
text = _file.read()
pre1 = "pre { color: #ffffff; background-color: #000000; "
pre2 = "font-size: 41px; }"
pre = pre1 pre2
text = re.sub("</style>", f"{pre}\n</style>", text)
_file.seek(0)
_file.write(text)
_file.truncate()
setup_jpg(html)
def get_subject(numbers, tag):
"""get_subject"""
subject = ""
for mining, number in numbers.items():
if mining == "ethermine":
goal = f"{tag['ethermine_goal_pm_usd']:06.2f}%"
# subject = f"ETM: ⛏️ E{number['usd']} 🎯{goal}"
subject = f"ETM⛏️💵{number['usd']}🏦{number['val']}"
if mining == "cryptoatcost":
goal = f"{tag['cryptoatcost_goal_pm_usd']:06.2f}%"
if subject != "":
subject = " "
# subject = f"CAC: ⛏️ B{number['usd']} 🎯{goal}"
subject = f"CAC⛏️💵{number['usd']}🏦{number['val']}"
if mining == "nicehash":
goal = f"{tag['nicehash_goal_pm_usd']:06.2f}%"
if subject != "":
subject = " "
# subject = f"NCH: ⛏️ B{number['usd']} 🎯{goal}"
subject = f"NCH⛏️💵{number['usd']}🏦{number['val']}"
return subject
def mail_data(params, numbers, tag):
"""mail_data"""
cfg = get_config()
if not cfg["mail_from"] or not cfg["mail_to"]:
print("Please set the FROM and TO fields of MAIL!")
sys.exit(0)
msg = MIMEMultipart()
msg["From"] = cfg["mail_from"]
msg["To"] = cfg["mail_to"]
msg["Subject"] = get_subject(numbers, tag)
name = PWD_DIR ".jpg"
filename = params["save_dir"] "/" name
with open(filename, "rb") as _file:
part = MIMEApplication(_file.read(), Name=name)
part["Content-Decomposition"] = f"attachment, filename={name}"
msg.attach(part)
smtp = smtplib.SMTP("localhost")
smtp.sendmail(msg["From"], msg["To"], msg.as_string())
smtp.close()
def telegram_send_msg(cfg, msg):
"""telegram_send_msg"""
send_text = (
f"https://api.telegram.org/bot{cfg['telegram_token']}"
f"/sendMessage?chat_id={cfg['telegram_id']}&parse_mode=Markdown&text={msg}"
)
# print(send_text)
response = requests.get(send_text)
# print(response)
# return response.json()
def telegram_data(params, numbers, tag, next_update):
cfg = get_config()
if not cfg["telegram_token"] or not cfg["telegram_id"]:
print("Please set the TOKEN and ID fields of TELEGRAM!")
subject = get_subject(numbers, tag)
telegram_send_msg(cfg, subject)
name = PWD_DIR ".jpg"
image_path = params["save_dir"] "/" name
data = {"chat_id": cfg["telegram_id"], "caption": ""}
url = f"https://api.telegram.org/bot{cfg['telegram_token']}/sendPhoto"
with open(image_path, "rb") as image_file:
response = requests.post(url, data=data, files={"photo": image_file})
# print(url, data, response.json())
msg, count = "", 0
msg = "✅" # msg = '🔳'
numbers = ["0️⃣", "1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣"]
msg = numbers[1]
next_update_str = next_update["timestamp"]
print(params)
if params["cryptoatcost"]:
crypto=params["cryptoatcost"].upper()
else:
crypto="BTC"
msg = f"🔜{next_update_str}x{crypto}"
telegram_send_msg(cfg, msg)
def get_params():
"""Get params"""
eth_addr = "0x0892c9b9b58ad5a7878d5dcd4da4ee72109c32c6"
email = "[email protected]"
parser = argparse.ArgumentParser(
add_help=False,
description=(
"Get wallet balance from Ethermine, Crytoatcost & Nicehash"
f" mining process.\nDonate ETH 👉 {eth_addr}"
f"\nContact email 👉 {email}"
),
formatter_class=RawTextHelpFormatter,
)
parser.add_argument(
"-c",
"--cryptoatcost",
type=str,
default="btc",
#dest="cryptoatcost",
help="Only show cryptoatcost info",
)
parser.add_argument(
"-e",
"--ethermine",
action="store_true",
default=False,
dest="ethermine",
help="Only show ethermine info",
)
parser.add_argument(
"-n",
"--nicehash",
action="store_true",
default=False,
dest="nicehash",
help="Only show nicehash info",
)
parser.add_argument(
"-r",
"--records",
type=int,
required=False,
default=-1,
help="The number of last records to get (0 = All)",
)
parser.add_argument(
"--columns",
type=int,
required=False,
default=-1,
help="The number of columns",
)
parser.add_argument(
"-s",
"--save_dir",
required=False,
default="",
help="Directory to save the output (HTML and JPG)",
)
hours = "3,7,11,15,19,23"
crontab = f"{hours} * * * /path/preview.py"
parser.add_argument(
"-u",
"--update",
action="store_true",
default=False,
dest="update",
help=(
"Only update database, crontab 👇\n"
"# Update data at minute 1 every 4 hours\n"
f"1 {crontab} -u"
),
)
parser.add_argument(
"-m",
"--mail",
action="store_true",
default=False,
dest="mail",
help=(
"Send an email with the image attachment, crontab 👇\n"
"# Send mail with a picture at minute 2 every 4 hours \n"
f"2 {crontab} -m"
),
)
parser.add_argument(
"-t",
"--telegram",
action="store_true",
default=False,
dest="telegram",
help="Send the data to telegram bot",
)
parser.add_argument(
"-h",
"--help",
action="store_true",
help="Show this help message and exit.",
)
parser.add_argument(
"-b",
action="store_true",
default=False,
dest="big",
help="Only show big text, like this 👇",
)
args = parser.parse_args()
if args.help or (
not args.ethermine and not args.cryptoatcost and not args.nicehash
):
parser.print_help()
console = Console()
_number = uniform(1.0, 9999.99)
if randint(0, 1):
_tag, _color = "^", "green"
else:
_tag, _color = "v", "red"
_fnumber = f"{_tag}${_number:5.2f}"
big_text.big_line(console, _fnumber, _color)
big_text.big_text(console, _fnumber, _color)
sys.exit(0)
cfg = get_config()
hostname = cfg["hostname"]
if args.mail or args.telegram:
args.save_dir = tempfile.gettempdir()
return {
"big": args.big,
"ethermine": args.ethermine,
"cryptoatcost": args.cryptoatcost,
"nicehash": args.nicehash,
"hostname": hostname,
"update": args.update,
"records": args.records,
"columns": args.columns,
"save_dir": args.save_dir,
"mail": args.mail,
"telegram": args.telegram,
}
def get_records(records, source, currency):
"""Get records and recalculate number of records"""
try:
if records == 0:
unpaids = (
Unpaid.select()
.where(
(Unpaid.source == source) & (Unpaid.currency == currency)
)
.order_by(Unpaid.work.desc(), Unpaid.step.desc())
)
else:
unpaids = (
Unpaid.select()
.where(
(Unpaid.source == source) & (Unpaid.currency == currency)
)
.order_by(Unpaid.work.desc(), Unpaid.step.desc())
.limit(records)
)
last_unpaid = unpaids[-1]
count, item = records - 1, 0
for unpaid in unpaids: # reversed(unpaids):
count -= 1
if count <= 0:
break
if unpaid.timestamp[:10] != last_unpaid.timestamp[:10]:
last_unpaid = unpaid
item = 1
item = 1 # First and Last
records -= item # Extra line of summary
unpaids = (
Unpaid.select()
.where(
(Unpaid.source == source) & (Unpaid.currency == currency)
)
.order_by(Unpaid.work.desc(), Unpaid.step.desc())
.limit(records)
)
except peewee.DoesNotExist:
print("do-something")
return records, unpaids
def set_missing():
"""Set Missing"""
# AQUI
timestamp = datetime.now().strftime(TS_FMT)
timestamp_obj = datetime.strptime(timestamp, TS_FMT)
if timestamp_obj > next_update["timestamp"]:
set_next_update(timestamp_obj, 4)
next_update["missing"] = next_update["timestamp"] - timestamp_obj
next_update["total_seconds"] = next_update["missing"].total_seconds()
def set_next_update(timestamp_obj, hours):
"""Set Next Update"""
next_update["timestamp"] = timestamp_obj timedelta(hours=hours)
next_update["timestamp"] = next_update["timestamp"].replace(
minute=2, second=0
)
def iterate_on_records(source, currency, table, params, data):
"""Iterate on records"""
tag = {}
tag["currency"] = "[cyan]"
params[f"records_{source}"], unpaids = get_records(
params[f"records_{source}"], source, currency
)
data["last_unpaid"] = None
delta = last_delta = {}
delta[source] = data["unpaid_save"]
item = 0
for unpaid in reversed(unpaids):
item = 1
if data["last_unpaid"] is None:
set_deltas_empty(unpaid, delta)
last_delta = delta.copy()
else:
last_delta = delta.copy()
set_deltas(data["last_unpaid"], unpaid, last_delta, delta)
tags_row(tag, data["last_unpaid"], unpaid, last_delta, delta)
if last_delta["date"] != delta["date"] or item == 1:
set_and_and_row_date(table, data["last_unpaid"], unpaid, delta)
data["lines_show"] -= 1
add_row(table, tag, delta, unpaid)
data["lines_show"] -= 1
if item == unpaids.count():
timestamp_obj = datetime.strptime(unpaid.timestamp, TS_FMT)
set_next_update(timestamp_obj, 4)
data["last_unpaid"] = unpaid
add_last_row(table, delta, data["last_unpaid"])
data["lines_show"] -= 4 # 1 Summary 3 Header
def show_data(console, params, unpaid_save, size_term):
"""Show time"""
if params["records"] == -1:
params["records"] = size_term["lines"]
if params["ethermine"] and params["cryptoatcost"]:
params["records"] = int(params["records"] / 2) # Sharing
params["records"] -= 4 # 3 Lines of header 1 of Footer
sources = []
if params["ethermine"]:
sources.append("ethermine")
params["records_ethermine"] = params["records"]
if params["cryptoatcost"]:
sources.append("cryptoatcost")
params["records_cryptoatcost"] = params["records"]
if params["nicehash"]:
sources.append("nicehash")
params["records_nicehash"] = params["records"]
lines_show = size_term["lines"] - 1
if lines_show < 3 and params["records"]:
print("Too small to show")
sys.exit(0)
print(chr(27) "[2J")
data = {
"lines_show": lines_show,
"next_update": next_update,
"last_unpaid": None,
"unpaid_save": unpaid_save,
}
tag = {}
for source in sources:
if source == "cryptoatcost":
currency = params["cryptoatcost"]
elif source == "nicehash":
currency = "btc"
else:
currency = "eth"
table = make_table()
iterate_on_records(source, currency, table, params, data)
timestamp = datetime.now().strftime(TS_FMT)
tags_title(tag, data["last_unpaid"], timestamp)
size_term = get_columns_and_lines(params)
msg = get_goal_msg(
source, currency, tag, data["last_unpaid"], size_term
)
console.print(
f"{tag['title']} ⛏️ {currency.upper()}@"
f"[bold white]{timestamp}[not bold black] "
f"{tag['ok']}{msg}[white on black][not bold] ",
style=tag["style"]
)
console.print(table)
if params["records"] != 0:
while data["lines_show"] > 0:
data["lines_show"] -= 1
console.print("")
if params["save_dir"]:
html = params["save_dir"] "/" PWD_DIR ".html"
console.save_html(html)
setup_html(html)
if "timestamp" not in next_update:
print("Nothing to do.")
sys.exit(0)
set_missing()
return next_update["total_seconds"], tag
def save_data(source, currency, value, usd):
"""Save record"""
if value == -1:
return 0
try:
unpaid = (
Unpaid.select()
.where((Unpaid.source == source) & (Unpaid.currency == currency))
.order_by(Unpaid.work.desc(), Unpaid.step.desc())
.get()
)
except peewee.DoesNotExist:
last_value, work, step = 0, 1, 1
else:
last_value, work, step = unpaid.value, unpaid.work, unpaid.step 1
timestamp = unpaid.timestamp
if last_value != value:
timestamp = f"{datetime.now()}"
timestamp_obj = datetime.strptime(timestamp, TS_FMT ".%f")
timestamp = timestamp_obj.strftime(TS_FMT)
unpaid = Unpaid(
source=source,
currency=currency,
work=work,
step=step,
timestamp=timestamp,
value=value,
usd=usd,
)
unpaid.save()
# pylint: disable=no-member
unpaid_save = unpaid.id
else:
unpaid_save = 0
return unpaid_save
def show_big(params, size_term):
"""Show big"""
datas = []
if params["ethermine"]:
datas.append(
{"source": "ethermine", "currency": "eth", "color": "white"}
)
if params["cryptoatcost"]:
datas.append(
{"source": "cryptoatcost", "currency": params["cryptoatcost"], "color": "white"}
)
if params["nicehash"]:
datas.append(
{"source": "nicehash", "currency": "btc", "color": "white"}
)
for data in datas:
source = data["source"]
currency = data["currency"]
unpaids = (
Unpaid.select()
.where((Unpaid.source == source) & (Unpaid.currency == currency))
.order_by(Unpaid.work.desc(), Unpaid.step.desc())
.limit(2)
)
if len(unpaids) >= 1:
data["usd_" source] = unpaids[0].usd
data["val_" source] = unpaids[0].value
if len(unpaids) == 2:
if unpaids[0].usd == unpaids[1].usd:
data["tag_usd"] = "="
data["color_usd"] = "white"
elif unpaids[0].usd > unpaids[1].usd:
data["tag_usd"] = "^"
data["color_usd"] = "green"
else:
data["tag_usd"] = "v"
data["color_usd"] = "red"
if unpaids[0].value == unpaids[1].value:
data["tag_val"] = "="
data["color_val"] = "white"
elif unpaids[0].value > unpaids[1].value:
data["tag_val"] = "^"
data["color_val"] = "green"
else:
data["tag_val"] = "v"
data["color_val"] = "red"
else:
data["tag_usd"] = data["tag_val"] = "="
data["color_usd"] = data["color_val"] = "white"
tags, colors, usds, cryptos, vals = {}, {}, {}, {}, {}
colors["normal"] = "black"
items = 0
if params["ethermine"]:
tags["usd_ethermine"] = datas[items]["tag_usd"]
tags["val_ethermine"] = datas[items]["tag_val"]
colors["usd_ethermine"] = datas[items]["color_usd"]
colors["val_ethermine"] = datas[items]["color_val"]
usds["usd_ethermine"] = datas[items]["usd_ethermine"]
cryptos["val_ethermine"] = datas[items]["currency"][0:1].upper()
vals["val_ethermine"] = datas[items]["val_ethermine"]
items = 1
if params["cryptoatcost"]:
tags["usd_cryptoatcost"] = datas[items]["tag_usd"]
tags["val_cryptoatcost"] = datas[items]["tag_val"]
colors["usd_cryptoatcost"] = datas[items]["color_usd"]
colors["val_cryptoatcost"] = datas[items]["color_val"]
usds["usd_cryptoatcost"] = datas[items]["usd_cryptoatcost"]
cryptos["val_cryptoatcost"] = datas[items]["currency"][0:1].upper()
vals["val_cryptoatcost"] = datas[items]["val_cryptoatcost"]
items = 1
if params["nicehash"]:
tags["usd_nicehash"] = datas[items]["tag_usd"]
tags["val_nicehash"] = datas[items]["tag_val"]
colors["usd_nicehash"] = datas[items]["color_usd"]
colors["val_nicehash"] = datas[items]["color_val"]
usds["usd_nicehash"] = datas[items]["usd_nicehash"]
cryptos["val_nicehash"] = datas[items]["currency"][0:1].upper()
vals["val_nicehash"] = datas[items]["val_nicehash"]
# print(vals)
console, numbers = big_text.show_big(usds, cryptos, vals, tags, colors, size_term)
# if params["cryptoatcost"]:
# big_text.show_big2(console, data["val_cryptoatcost"])
# if params["nicehash"]:
# big_text.show_big2(console, data["val_nicehash"])
return console, numbers
def show_chart(console, params, size_term):
sources = []
if params["cryptoatcost"]:
sources.append({ "source": "cryptoatcost", "crypto": params["cryptoatcost"] })
if params["nicehash"]:
sources.append({ "source": "nicehash", "crypto": "btc" })
for source in sources:
text = chart_text.show_chart(source["source"], source["crypto"], size_term)
# print(text)
colors = ["cyan", "magenta"]
c = 0
line = ""
lines = []
for char in text:
line = char if not char == "\n" else ""
if char == "\n":
lines.append(line)
line = ""
chart = 0
tag_color = ""
for line in lines:
if "Mining" in line:
color = colors[chart]
tag_color = f"[{color} on black]"
chart = 1
console.print(f"{tag_color}{line}")
def get_data_remote(params):
"""Get data using another host"""
pwd = os.path.dirname(os.path.realpath(__file__))
cmd = f"{pwd}/mining/cryptoatcost.py"
crypto = params['cryptoatcost'].upper()
result = subprocess.Popen(
f"ssh {params['hostname']} {cmd} {crypto}",
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
).communicate()
data = result[0].decode("utf-8").rstrip("\n")
lst_data = data.split(" ")
val_cac, usd_cac = float(lst_data[1]), float(lst_data[3])
cmd = f"{pwd}/staking/cryptoatcost.py"
crypto = params['cryptoatcost'].upper()
result = subprocess.Popen(
f"ssh {params['hostname']} {cmd} {crypto}",
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
).communicate()
data = result[0].decode("utf-8").rstrip("\n")
lst_data = data.split(" ")
val2_cac, usd_cac2 = float(lst_data[1]), float(lst_data[3])
return val_cac val2_cac, usd_cac usd_cac2
def get_data_local(crypto):
"""Get data using this host"""
cacpanel = mining.cryptoatcost.CACPanel()
val_cac, usd_cac = cacpanel.wallet(crypto.upper())
cacpanel = staking.cryptoatcost.CACPanel()
val_cac2, usd_cac2 = cacpanel.wallet(crypto.upper())
return val_cac val_cac2, usd_cac usd_cac2
def get_data(params, size_term):
"""Get data from miner"""
if params["ethermine"]:
source, currency = "ethermine", "eth"
etmpanel = mining.ethermine.ETMPanel()
eth, usd_etm = etmpanel.wallet()
unpaid_save_etm = save_data(source, currency, eth, usd_etm)
else:
unpaid_save_etm = 0
if params["cryptoatcost"]:
source, currency = "cryptoatcost", params['cryptoatcost']
try:
if (
params["hostname"]
and params["hostname"] != socket.gethostname()
):
val_cac, usd_cac = get_data_remote(params)
else:
val_cac, usd_cac = get_data_local(params['cryptoatcost'])
#print(source, currency, val_cac, usd_cac)
unpaid_save_cac = save_data(source, currency, val_cac, usd_cac)
#print(unpaid_save_cac)
except mining.cryptoatcost.MaintenanceMode:
unpaid_save_cac = 0
else:
unpaid_save_cac = 0
if params["nicehash"]:
source, currency = "nicehash", "btc"
nchpanel = mining.nicehash.NCHPanel()
btc, usd_nsh = nchpanel.wallet()
unpaid_save_nsh = save_data(source, currency, btc, usd_nsh)
else:
unpaid_save_nhs = 0
console, numbers = show_big(params, size_term)
return console, numbers, {"etm": unpaid_save_etm, "cac": unpaid_save_cac}
def do_loop():
"""Eternal Loop 4 forever & ever"""
setup_db()
params = get_params()
size_term = get_columns_and_lines(params)
while True:
console, numbers, unpaid_save = get_data(params, size_term)
if params["big"]:
return
if params["update"]:
timestamp = datetime.now().strftime(TS_FMT)
id_save = unpaid_save
print(f"{timestamp} => {id_save}")
return
show_chart(console, params, size_term)
seconds, tag = show_data(console, params, unpaid_save, size_term)
if params["telegram"]:
telegram_data(params, numbers, tag, next_update)
if params["mail"]:
mail_data(params, numbers, tag)
if params["records"] == 0 or params["save_dir"] or params["mail"]:
return
try:
show_progress(seconds, next_update)
except KeyboardInterrupt:
sys.exit(0)
do_loop()