-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram.py
134 lines (117 loc) · 4.53 KB
/
program.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
from datetime import datetime
import sys
import threading
import time
import os
from assets.helper import CODE
from replicator_sender import ReplicatorSender
from writer import Writer
from ReplicatorReceiver.Logger import Logger
from ReplicatorReceiver.Receiver import ReplicatorReceiver
class NevalidanUnos(Exception):
def __init__(self, message=None):
self.message = message
def __str__(self):
if self.message is None:
return "Nevalidan unos."
return self.message
def main():
writer = Writer()
threads = []
l: Logger = Logger(r"C:\Users\Pantex\PycharmProjects\pythonProject\BazaPodataka\LOG\UILogs.txt")
data = ReplicatorReceiver()
ret: int
while True:
# print(CODE.CODE_CUSTOM.name)
print("Pritisni dugme za Meni")
if len(threads) == 0:
print("Nema upaljenih writera.")
input()
ret = Meni()
if ret == 1:
writer.stop_threads = False
threads.append(threading.Thread(target=writer.writer_send_data))
threads[len(threads) - 1].start()
dateTime = datetime.now().strftime("%d-%m-%y %H:%M:%S")
print(f"Upaljeno {len(threads)} writera")
l.LoggActivity(f"Upaljen novi writer.Trenutno writera -> {len(threads)} ", dateTime)
elif ret == 2:
writer.stop_threads = True
time.sleep(1)
threads[len(threads) - 1].join()
threads.clear()
dateTime = datetime.now().strftime("%d-%m-%y %H:%M:%S")
l.LoggActivity(f"Ugaseni writeri.", dateTime)
elif ret == 3:
br = iscitavanje_po_vr_intervalu()
if br is not None:
code1 = br[0]
odDatuma1 = br[1]
doDatuma1 = br[2]
data.send_to_read(code1, odDatuma1, doDatuma1)
elif ret == 4:
code2 = iscitavanje_poslednje_vrednosti()
if code2 is not None:
data.send_to_read2(code2)
elif ret == 5:
continue
elif ret == 6:
break
else:
print("Nepostojeca komanda")
print("Gasenje")
sys.exit()
def iscitavanje_poslednje_vrednosti():
print("CODE_ANALOG, CODE_DIGITAL, CODE_CUSTOM,"
"CODE_LIMITSET, CODE_SINGLENODE, CODE_MULTIPLENODE, CODE_CONSUMER, CODE_SOURCE")
print("Unesite neku od vrednosti iznad koje zelite da iscitate:")
code = input()
try:
if code != "CODE_ANALOG" and code !="CODE_DIGITAL" and code !="CODE_CUS" \
"TOM" and code !="CODE_SINGLENODE" and code !="CODE_MULTIPLENO" \
"DE" and code != "CODE_CONSUMER" and code !="CODE_SOURCE" and code !="CODE_LIMITSET":
raise NevalidanUnos("Pogresan unos!Unesite neke od navedenih kodova")
return code
except NevalidanUnos as e:
print(e)
return None
def iscitavanje_po_vr_intervalu():
while True:
print("CODE_ANALOG, CODE_DIGITAL, CODE_CUSTOM,"
" CODE_LIMITSET, CODE_SINGLENODE, CODE_MULTIPLENODE, CODE_CONSUMER, CODE_SOURCE")
print("Unesite neku od vrednosti iznad koje zelite da iscitate:")
code = input()
if code != "CODE_ANALOG" and code != "CODE_DIGITAL" and code != "CODE_CUS" \
"TOM" and code != "CODE_SINGLENODE" and code != "CODE_MULTIPLENO" \
"DE" and code != "CODE_CONSUMER" and code != "CODE_SOURCE" and code != "CODE_LIMITSET":
print(NevalidanUnos("Pogresan unos!Unesite neke od navedenih kodova"))
return None
else:
print("Unesite od kog datuma zelite da iscitate u formatu 'dan-mesec-godina sati:minuti:sekunde' ")
odDatuma = input()
print("Unesite do kog datuma zelite da iscitateu formatu 'dan-mesec-godina sati:minuti:sekunde' ")
doDatuma = input()
pom = [code, odDatuma, doDatuma]
return pom
def Meni():
while True:
print("1.Upali writera")
print("2.Ugasi writere")
print("3.Citanje vrednosti readera po vremenskom intervalu za trazeni kod")
print("4.Dobavljanje poslednje vrenosti izabranog koda")
print("5.Odustani")
print("6.Ugasi klijenta")
br = input()
try:
br = int(br)
if br <= 0 or br > 6:
raise NevalidanUnos("Pogresan unos!")
return br
except NevalidanUnos as e:
print(e)
return None
except Exception:
print("Unesite broj.")
return None
if __name__ == "__main__":
main()