-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.py
More file actions
78 lines (65 loc) · 3.17 KB
/
Copy pathui.py
File metadata and controls
78 lines (65 loc) · 3.17 KB
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
import sys
ts = 34
class UI:
def dynamic_progress_bar(self, percentage, width=ts*2):
spaces = ' ' * (width - len(self.trackLine['start']['staz']) - len(self.trackLine['end']['staz']) - 1)
sys.stdout.write(f'{self.trackLine["start"]["staz"]} {spaces} {self.trackLine["end"]["staz"]}\n')
progress = percentage / 100.0
arrow = '=' * int(round(progress * width) - 1)
spaces = ' ' * (width - len(arrow) -1)
sys.stdout.write(f'\r[{arrow}{spaces}] {int(percentage)}%')
sys.stdout.flush()
def __init__(self):
self.gps = {"isGpsValid":True,"ultimaStazione":"--","eta":"--", "speed":"--","delay":"--", "isOdoValid":False,"tracknum":"--", "isTrackOnGPS": True, "delay2": "--", "postreno": "--"}
self.trackLine = {"start": {"staz": "--"}, "trainprogress": 0, "postreno": 0.0, "mid": {"staz": "--"}, "end": {"staz": "--"}}
self.stops = []
def _clear_terminal(self):
print("\033[2J")
print("\033[0;0f")
def _print_train(self):
sys.stdout.write("\033[001m")
sys.stdout.write("\x1b[38;2;252;65;3m")
sys.stdout.write(" __ __\n")
sys.stdout.write(" /' `\\\n")
sys.stdout.write(" Y. .Y\n")
sys.stdout.write(" _______ \\`. .'/\n")
sys.stdout.write(" ,-------------'=======\"--\"\"\"\"-\"\"\"\"---.\n")
sys.stdout.write(" __,=+'-------------------------------------|\n")
sys.stdout.write(" .-/__|_]_] :\"/:\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"|\n")
sys.stdout.write(" ,-'__________[];/_;_____F R E C C I A R O S S A__|\n")
sys.stdout.write(" ,\".../_|___________________________________________|\n")
sys.stdout.write(" (_> ,-------. ,-------. |\n")
sys.stdout.write(" `-._____.'(_)`='(_)\\_7___7___7___7__7_.'(_)`='(_)\\_/\n")
sys.stdout.write("\033[000m")
sys.stdout.flush()
def printError(self):
self._clear_terminal()
# self._print_train()
sys.stdout.write("\033[001m")
sys.stdout.write("\x1b[38;2;252;65;3m")
sys.stdout.write('='*ts +" Error " + '='*(ts-1)+"\n")
sys.stdout.write("\033[000m")
print("The train is not providing valid data :(\n")
def print(self):
self._clear_terminal()
self._print_train()
sys.stdout.write("\033[001m")
sys.stdout.write("\x1b[38;2;194;245;66m")
sys.stdout.write("\n" + '='*ts +" Data " + '='*ts+"\n")
sys.stdout.write("\033[000m")
print(f"Speed: {self.gps['speed']} km/h")
print(f"Delay: {self.gps['delay']}")
sys.stdout.write("\033[001m")
sys.stdout.write("\x1b[38;2;66;245;99m")
sys.stdout.write("\n" + '='*(ts-2) +" Progress " + '='*(ts-2)+"\n")
sys.stdout.write("\033[000m")
self.dynamic_progress_bar(self.trackLine['postreno'])
print("\n")
sys.stdout.write("\033[001m")
sys.stdout.write("\x1b[38;2;245;179;66m")
sys.stdout.write("\n" + '='*ts +" Stops " + '='*(ts-1)+"\n")
sys.stdout.write("\033[000m")
if len(self.stops) == 0:
print(" No stops information....")
for stop in self.stops:
print(f" - {stop['description'].title():40s} Arrival time: {stop['orario']}")