-
Notifications
You must be signed in to change notification settings - Fork 1
/
helper_utils.py
47 lines (38 loc) · 1.09 KB
/
helper_utils.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
import os
import platform
import time
from typing import Iterator
import psutil
from download_card_defs import download_collectable
def hs_running():
for pid in psutil.pids():
if psutil.pid_exists(pid):
try:
if 'Hearthstone' in psutil.Process(pid).name():
return True
except:
pass
return False
if platform.system() == 'Windows':
clear_console = lambda: os.system('cls')
else:
clear_console = lambda: os.system('clear')
def follow_file(file, sleep_sec=0.1) -> Iterator[str]:
line = ''
while True:
tmp = file.readline()
if tmp is not None and tmp != "":
line += tmp
if line.endswith("\n"):
yield line
line = ''
elif hs_running():
time.sleep(sleep_sec)
else:
break
yield ''
def download_card_data():
if not os.path.exists("./helper_data"):
os.mkdir("./helper_data")
if not os.path.exists("./helper_data/cards.collectible.json"):
download_collectable("./helper_data")