first commit

This commit is contained in:
2025-11-05 18:29:49 +03:00
commit a80c03a27d
41 changed files with 7713 additions and 0 deletions

123
old/timer_MBA.py Normal file
View File

@@ -0,0 +1,123 @@
from socket import *
from datetime import datetime
import json
import time
HOST = "10.0.0.57" # local
PORT = 50002
ADDR = (HOST,PORT)
PATH = "D:\\timer.json"
def connect():
tcp_socket = socket(AF_INET, SOCK_STREAM)
tcp_socket.connect(ADDR)
data = "Hello, world"
data = str.encode(data)
tcp_socket.send(data)
data = bytes.decode(data)
data = tcp_socket.recv(1024)
# tcp_socket.close()
return data
def save_log(name, data):
current_time = datetime.now().strftime("%d-%m-%Y %H:%M:%S.%f")
message_with_time = f"[{current_time}] {data}"
with open(name, "a") as file:
file.write(message_with_time + "\n")
def formatted_data(data):
save_log("logs_mba.txt", data)
# data_converted = list(data)
# data_formatted = [
# str(hex_value // 16) + str(hex_value % 16) for hex_value in data_converted
# ]
# save_log("logs_mba_formatted.txt", data_formatted)
def parse(data_formatted):
# print(len(data_formatted))
# print(data_formatted)
with open(PATH, "r", encoding="utf-8") as f:
new_data = json.load(f)
new_data = new_data[0]
if len(data_formatted) > 30:
if data_formatted[17] == "010":
if data_formatted[-8] in ["01", "05"]:
timer_str = (
f"{int(data_formatted[-7])}:{data_formatted[-6]}"
if int(data_formatted[-7]) != 0
else f"{int(data_formatted[-6])}.{int(data_formatted[-5])}"
)
new_data["timeGFX"] = timer_str
new_data["minutesGFX"] = int(
data_formatted[-7]
) # [25] #data_formatted[17] = 010 - таймер data_formatted[-8] = 05 - овертайм, 06 - перерыв между основным временем и овертаймом, 01 - игровое время, 02 - перерыв между периодами
new_data["secondsGFX"] = data_formatted[-6] # [26]
else:
timer_str = f"{int(data_formatted[-7])}:{data_formatted[-6]}"
new_data["timeNotGame"] = timer_str
if len(data_formatted) == 58:
new_data[
"timeDel1"
] = f"{int(data_formatted[26])}:{data_formatted[27]}" # data_formatted[17] = 24 - удаление
new_data["timeDel2"] = f"{int(data_formatted[41])}:{data_formatted[42]}"
try:
with open(PATH, "w", encoding="utf-8") as file:
json.dump([new_data], file, ensure_ascii=False, indent=4)
print(new_data)
except Exception:
pass
def main():
with socket(AF_INET, SOCK_STREAM) as s:
s.connect((HOST, PORT))
s.sendall(b"Hello, world")
data = s.recv(1024)
while True:
print(data)
data_new = formatted_data(data)
time.sleep(.1)
# parse(data)
def read_logs():
import time
with open("test_logs_balashikha_new.txt", "r") as file:
for line in file:
parts = line.strip().split("] ")
if len(parts) == 2:
timestamp = parts[0][1:]
data = parts[1]
parse(eval(data))
if len(eval(data)) > 30 and eval(data)[-7] == "00":
time.sleep(.1)
else:
time.sleep(1)
if __name__ == "__main__":
new_data = {
"timeGFX": "0:00",
"minutesGFX": "0",
"secondsGFX": "0",
"foul1": "0",
"foul2": "0",
"quarter": "0",
}
with open(PATH, "w", encoding="utf-8") as file:
json.dump([new_data], file, ensure_ascii=False, indent=4)
main()
# read_logs()

143
old/timer_MBA_2.py Normal file
View File

@@ -0,0 +1,143 @@
import sys
import json
from socket import *
from datetime import datetime
import time
host = "10.0.0.57"
port = 50002
ADDR = (host, port)
PATH = "D:\\timer_basketball.json"
def save_log(name, data):
current_time = datetime.now().strftime("%d-%m-%Y %H:%M:%S.%f")
message_with_time = f"[{current_time}] {data}"
with open(name, "a") as file:
file.write(message_with_time + "\n")
def parse(data):
data = data.split("/")
with open(PATH, "r", encoding="utf-8") as f:
new_data = json.load(f)
new_data = new_data[0]
path_pic = "D:\Графика\БАСКЕТБОЛ\ЕДИНАЯ ЛИГА ВТБ 2022-2023\VTB_Fouls for scoreboard smaller"
if len(data) > 10:
if data[4] == "NPR":
new_data["quarter"] = data[5]
if data[17] == "HCP":
new_data["points1"] = data[18]
if data[20] == "GCP":
new_data["points2"] = data[21]
if data[29] == "HCF":
new_data["foul1"] = data[30]
new_data["foul_pic1"] = path_pic + f"\Home тАУ {int(data[30])} Foul.png"
if data[32] == "GCF":
new_data["foul2"] = data[33]
new_data["foul_pic2"] = path_pic + f"\Away тАУ {int(data[33])} Foul.png"
else:
if data[1] == "TGI":
if data[2] != "0":
seconds = data[3] if len(data[3]) != 1 else f"0{data[3]}"
new_data["timeGFX"] = f"{data[2]}:{seconds}"
else:
millisec = data[4]
if millisec == "#":
millisec = "0"
new_data["timeGFX"] = f"{data[3]}.{millisec}"
elif data[1] == "NPR":
new_data["quarter"] = data[2]
elif data[1] == "HCP":
new_data["points1"] = data[2]
elif data[1] == "GCP":
new_data["points2"] = data[2]
elif data[1] == "HCF":
new_data["foul1"] = data[2]
new_data["foul_pic1"] = path_pic + f"\Home тАУ {int(data[2])} Foul.png"
elif data[1] == "GCF":
new_data["foul2"] = data[2]
new_data["foul_pic2"] = path_pic + f"\Away тАУ {int(data[2])} Foul.png"
elif data[1] == "TAI":
if data[2] not in ["0", "-1"]:
new_data["time_attackGFX"] = str(int(data[2]))
if int(data[2]) <= 5:
new_data["time_attac_pic"] = ""
else:
new_data["time_attac_pic"] = "empty"
try:
with open(PATH, "w", encoding="utf-8") as file:
json.dump([new_data], file, ensure_ascii=False, indent=4)
print(new_data)
if ":" in new_data["timeGFX"]:
time.sleep(.5)
else:
time.sleep(.1)
except Exception:
pass
def read_logs():
with open("logs_mba_1.txt", "r") as file:
for line in file:
parts = line.strip().split("] ")
if len(parts) == 2:
timestamp = parts[0][1:]
data = parts[1]
parse(data)
# if len(eval(data)) > 30 and eval(data)[-7] == "00":
# time.sleep(.1)
# else:
# time.sleep(1)
def main():
new_data = {
"timeGFX": "0:00",
"time_attackGFX": "",
"quarter": "0",
"points1": "0",
"points2": "0",
"foul1": "0",
"foul2": "0",
"foul_pic1": "",
"foul_pic2": "",
"time_attac_pic": "",
}
with open(PATH, "w", encoding="utf-8") as file:
json.dump([new_data], file, ensure_ascii=False, indent=4)
# tcp_socket = socket(AF_INET, SOCK_STREAM)
# tcp_socket.connect(ADDR)
# try:
# while True:
# data = str.encode("hello")
# tcp_socket.send(data)
# data = bytes.decode(data)
# data = tcp_socket.recv(1024)
# data = data.decode()
# save_log("logs_mba_1.txt", data)
# parse(data)
# except KeyboardInterrupt:
# tcp_socket.close()
# sys.exit(1)
if __name__ == "__main__":
try:
main()
read_logs()
except KeyboardInterrupt:
sys.exit(1)

141
old/timer_Megasport_test.py Normal file
View File

@@ -0,0 +1,141 @@
import sys
import json
from socket import *
from datetime import datetime
import logging
import os
import time
import binascii
HOST = "192.168.127.254"
PORT = 1993
PATH = (
r"D:\ГРАФИКА\БАСКЕТБОЛ\ЕДИНАЯ ЛИГА ВТБ 2022-2023\python\JSON\timer_basketball.json"
)
def hexspace(string, length):
return " ".join(string[i : i + length] for i in range(0, len(string), length))
def parse(line):
cdata = binascii.hexlify(line)
ddata = cdata.decode("utf-8").upper()
edata = hexspace(ddata, 2)
if len(edata.split()) == 33:
temp_data = edata.split()
temp_new = [int(t, 16) for t in temp_data]
minutes = temp_new[6]
seconds = temp_new[7]
milliseconds = temp_new[8]
timer_str = (
f"{minutes}:{seconds:02d}"
if minutes != 0
else f"{seconds:02d}.{milliseconds}"
)
active_temp = temp_new[
9
] # 133 - таймер идёт | 132 - таймер стоит | 128 - не игровое время стоит | 129 - не игровое время идёт
if temp_new[-2] != 0:
time_attack = (
temp_new[-4] if temp_new[-4] > 4 else f"{temp_new[-4]}.{temp_new[-3]}"
)
else:
time_attack = "" # temp_new[-2] == 1 - таймер идёт | 2 - таймер стоит | 0 - таймер не отображён
# print(f"{str(temp_new):<120}__{timer_str:<7}__{time_attack:<3}__")
else:
temp_data = edata.split()
temp_new = [int(t, 16) for t in temp_data]
with open("timer_NN.csv", "a+") as file:
file.write(str(temp_new))
file.write("\n")
with open("timer_NN_2.csv", "a+") as file:
file.write(str(temp_data))
file.write("\n")
with open("timer_NN_3.csv", "a+") as file:
file.write(str(ddata))
file.write("\n")
# time.sleep(0.1)
def read_logs():
with open("timer_NN_2023-12-20_18-17-29.log", "r") as file:
# with open("timer_NN_test.log", "r") as file:
temp_line = ""
for line in file:
parts = line.strip().split(" DEBUG ")
if len(parts) == 2:
timestamp = parts[0][1:]
data = eval(parts[1])
parse(data)
time.sllep(.1)
# if len(eval(data)) > 30 and eval(data)[-7] == "00":
# time.sleep(.1)
# else:
# time.sleep(1)
def main():
# current_time = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
# if not os.path.isdir("LOGS"):
# os.mkdir("LOGS")
# LogFileName = f"LOGS/timer_Chine_tcp_{current_time}.log"
# logging.basicConfig(
# level=logging.DEBUG,
# format="%(asctime)s %(levelname)s %(message)s",
# filename=LogFileName,
# filemode="w",
# )
# new_data = {
# "timeGFX": "0:00",
# "time_attackGFX": "",
# "quarter": "0",
# "points1": "0",
# "points2": "0",
# "foul1": "0",
# "foul2": "0",
# "foul_pic1": "",
# "foul_pic2": "",
# "time_attac_pic": "",
# }
# with open(PATH, "w", encoding="utf-8") as file:
# json.dump([new_data], file, ensure_ascii=False, indent=4)
try:
tcp_socket = socket(AF_INET, SOCK_STREAM)
tcp_socket.connect((HOST, PORT))
data = str.encode("hello")
tcp_socket.send(data)
data = bytes.decode(data)
while True:
data = tcp_socket.recv(1024)
# logging.debug(data)
cdata = binascii.hexlify(data)
ddata = cdata.decode("utf-8").upper()
edata = hexspace(ddata, 2)
print(edata)
# temp_data = edata.split()
# temp_new = [int(t, 16) for t in temp_data]
# timer = f"{temp_new[3]}:{temp_new[2]}"
# seconds = temp_new[5]
# milliseconds = str(temp_new[4])[0]
# print(f"data: {edata}", temp_new, timer, f"{seconds}.{milliseconds}")
# print(temp_new, timer, f"{seconds}.{milliseconds}")
except KeyboardInterrupt:
tcp_socket.close()
sys.exit(1)
if __name__ == "__main__":
try:
main()
# read_logs()
except KeyboardInterrupt:
sys.exit(1)

82
old/timer_megasport.py Normal file
View File

@@ -0,0 +1,82 @@
# import serial.tools.list_ports #pip install pyserial
import serial
from datetime import datetime
import json
# Configure the COM port
port = "COM8" # Replace with the appropriate COM port name
baudrate = 9600
# baudrate = 19200
PATH = "D:\\timer_basketball.json"
def save_log(name, data):
current_time = datetime.now().strftime("%d-%m-%Y %H:%M:%S.%f")
message_with_time = f"[{current_time}] {data}"
with open(name, "a") as file:
file.write(message_with_time + "\n")
def read_logs():
import time
with open("logs_megasport_formatted.txt", "r") as file:
for line in file:
parts = line.strip().split("] ")
if len(parts) == 2:
timestamp = parts[0][1:]
data = parts[1]
parse(eval(data))
input()
# if len(eval(data)) > 30 and eval(data)[-7] == "00":
# time.sleep(0.1)
# else:
# time.sleep(1)
def parse(data_formatted):
print(len(data_formatted))
if len(data_formatted) > 8:
print(data_formatted)
with open(PATH, "r", encoding="utf-8") as f:
new_data = json.load(f)
new_data = new_data[0]
def main():
try:
# Open the COM port
ser = serial.Serial(port, baudrate=baudrate)
print("Serial connection established.")
while True:
line = ser.readline()
line = list(line)
line = [str(hex_value // 16) + str(hex_value % 16) for hex_value in line]
save_log("logs_balashikha_formatted.txt", line)
print(line)
except serial.SerialException as se:
print("Serial port error:", str(se))
except KeyboardInterrupt:
exit(1)
finally:
if ser.is_open:
ser.close()
print("Serial connection closed.")
if __name__ == "__main__":
# new_data = {
# "timeGFX": "0:00",
# }
# with open(PATH, "w", encoding="utf-8") as file:
# json.dump([new_data], file, ensure_ascii=False, indent=4)
main()
# read_logs()

70
old/timer_megasport2.py Normal file
View File

@@ -0,0 +1,70 @@
import serial
from serial import SerialException
import logging
import time
import binascii
SerialPort = "COM1"
BaudRate = 19200
PackageByTime = 0.1
PackageByLenght = 256
BufferMax = 2000
LogFileName = "megasport_new_4.log"
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(levelname)s %(message)s',
filename=LogFileName,
filemode="w")
ser = serial.Serial()
ser.port = SerialPort
ser.baudrate = BaudRate
ser.bytesize = serial.EIGHTBITS
ser.parity = serial.PARITY_NONE
ser.stopbits = serial.STOPBITS_ONE
ser.timeout = PackageByTime
ser.xonxoff = False
ser.rtscts = False
ser.dsrdtr = False
ser.write_timeout = 2
start = b"\xe0\xe0\xe8\xe8\xe4\xe4\xf8"
finish = b"\r"
while True:
try:
print("Initializing")
ser.close()
ser.open()
if ser.is_open:
try:
RequestCount = 0
print("Port Opening")
RetryCount = 0
remainder_hex = b""
while True:
response = ser.read(PackageByLenght)
print(response)
logging.debug(response)
if len(response) > 0:
StarterTime = time.time() * 1000
response_hex = response.replace(b" ", b"")
try:
int(response_hex,16)
except ValueError:
response_hex = binascii.hexlify(response)
response_hex = response_hex.upper()
response_hex = remainder_hex + response_hex
print(response_hex)
except Exception as e1:
logging.error("error communicating...: " + str(e1))
else:
print("Port Opening Failed... trying again in 5 seconds")
time.sleep(5)
ser.close()
except SerialException:
print("No port connected... trying again in 5 seconds")
time.sleep(5)

58
old/timer_megasport3.py Normal file
View File

@@ -0,0 +1,58 @@
import serial
from serial import SerialException
import logging
import time
import binascii
SerialPort = "COM1"
BaudRate = 19200
PackageByTime = 0.1
PackageByLenght = 256
BufferMax = 2000
LogFileName = "megasport_new_4.log"
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(levelname)s %(message)s',
filename=LogFileName,
filemode="w")
ser = serial.Serial()
ser.port = SerialPort
ser.baudrate = BaudRate
ser.bytesize = serial.EIGHTBITS
ser.parity = serial.PARITY_NONE
ser.stopbits = serial.STOPBITS_ONE
ser.timeout = PackageByTime
ser.xonxoff = False
ser.rtscts = False
ser.dsrdtr = False
ser.write_timeout = 2
# start = b"\xf8"
# finish = b"\r"
while True:
try:
print("Initializing")
ser.close()
ser.open()
if ser.is_open:
try:
RequestCount = 0
print("Port Opening")
RetryCount = 0
remainder_hex = b""
while True:
response = ser.read(PackageByLenght)
print(response)
logging.debug(response)
except Exception as e1:
logging.error("error communicating...: " + str(e1))
else:
print("Port Opening Failed... trying again in 5 seconds")
time.sleep(5)
ser.close()
except SerialException:
print("No port connected... trying again in 5 seconds")
time.sleep(5)

261
old/timer_megasport5.py Normal file
View File

@@ -0,0 +1,261 @@
import serial
from serial import SerialException
import datetime
import binascii
import logging
import time
import json
import re
# Configuration Data (later to be put in Panel2Net.conf)
# SerialPort: Name of RPi serial port receiving the panel data
# SerialPort = "COM1"
SerialPort = "COM2"
# BaudRate: Serial port speed (Baud, Default will be adjusted later)
BaudRate = 19200
# PackageByTime: Time Duration until a package is closed
# and sent off (seconds)
PackageByTime = 0.1
# PackageByLength* Length (in bytes) of data input
# until a package is closed and sent off
PackageByLength = 128
# PackageByLength = 256 попробовать нужно !!!!!!!!!!!!!!!!!!!!
# PackageByLength = 80
# MaxBuffer before flushing (in order to avoid buffer overflow)
BufferMax = 2000
# LogFileName: Name of LogFile
current_time = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
LogFileName = f"timer_megasport5_{current_time}.log"
# LogFileSize Maximum Size of LogFile (in Mbytes)
LogFileSize = 10
# LogLevel Minimum Severity Level to be logged (see severity in Logs)
LogLevel = "E"
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s %(levelname)s %(message)s",
filename=LogFileName,
filemode="w",
)
def hexspace(string, length):
return ' '.join(string[i:i+length] for i in range(0,len(string),length))
ser = serial.Serial()
ser.port = SerialPort
ser.baudrate = BaudRate
ser.bytesize = serial.EIGHTBITS
# number of bits per bytes
ser.parity = serial.PARITY_NONE
# set parity check: no parity
ser.stopbits = serial.STOPBITS_ONE
# number of stop bits
ser.timeout = PackageByTime
# non-block read
ser.xonxoff = False
# disable software flow control
ser.rtscts = False
# disable hardware (RTS/CTS) flow control
ser.dsrdtr = False
# disable hardware (DSR/DTR) flow control
ser.writeTimeout = 2
# timeout for write
PATH = (
r"D:\ГРАФИКА\БАСКЕТБОЛ\ЕДИНАЯ ЛИГА ВТБ 2022-2023\python\JSON\timer_basketball.json"
)
new_data = {
"timeGFX": "0.0",
"time_attackGFX": "",
"quarter": "0",
"points1": "0",
"points2": "0",
"foul1": "0",
"foul2": "0",
"foul_pic1": "",
"foul_pic2": "",
"time_attac_pic": "",
}
with open(PATH, "w", encoding="utf-8") as file:
json.dump([new_data], file, ensure_ascii=False, indent=4)
while True:
try:
print("Initializing")
ser.close()
ser.open()
if ser.is_open:
try:
ser.reset_input_buffer()
# flush input buffer, discarding all its contents
ser.reset_output_buffer()
# flush output buffer, aborting current output
# and discard all that is in buffer
RequestCount = 0
print("Port Opening")
# Initialise RetryCounter
RetryCount = 0
# Initialise Variable to take remainder string
remainder_hex = b""
while True:
# Read from Serial Interface
response = ser.read(PackageByLength)
# print(response)
if len(response) > 0:
# In case there is something coming down the serial path
logging.debug(response)
if response != b"":
data = response
# debug line
# f.write(data)
# f.write("\n")
cdata = binascii.hexlify(data)
ddata = cdata.decode('utf-8')
ddata = ddata.upper()
print (ddata)
edata = hexspace(ddata, 2)
print (edata)
# points1 = ""
# points2 = ""
# quarter = ""
# data_str = response.decode(
# "ascii", errors="ignore"
# ).replace("\r", "|")
# if len(data_str) == 53:
# pattern = r"^(3 0|7 |8 |69i553 |69i557 |69i558 |5:i553 )(.{4})"
# matches = re.findall(pattern, data_str)
# for match in matches:
# found_value = match[0]
# timer_str = match[1]
# if match[0] == "3 0":
# points1 = data_str[7:10].strip()
# points2 = data_str[10:13].strip()
# quarter = data_str[13:14].strip()
# # print(f"Следующие 4 символа: {timer_str}, Найдено: {found_value}, {data_str}_____")
# else:
# pattern = r"(\|3 0|\|7 |\|8 |\|69i553 |\|69i557 |\|69i558 |\|5:i553 )(.{4})"
# matches = re.findall(pattern, data_str)
# # print(data_str)
# for match in matches:
# found_value = match[0]
# timer_str = match[1]
# if match[0] == "3 0":
# points1 = data_str[7:10].strip()
# points2 = data_str[10:13].strip()
# quarter = data_str[13:14].strip()
# # print(f"Следующие 4 символа: {timer_str}, Найдено: {found_value}, {data_str}_____")
# pattern_attack = r"(.{5})\|"
# matches_attack = re.findall(pattern_attack, data_str)
# path_pic = r"D:\ГРАФИКА\БАСКЕТБОЛ\ЕДИНАЯ ЛИГА ВТБ 2022-2023\Scorebug Indicators"
# try:
# if matches_attack[0][2:] == "030":
# time_attackGFX = ""
# time_attac_pic = path_pic + "\\24Sec_empty.png"
# else:
# hex_dict = {
# "I": 9,
# "H": 8,
# "G": 7,
# "F": 6,
# "E": 5,
# "D": 4,
# "C": 3,
# "B": 2,
# "A": 1,
# }
# time_attackGFX = matches_attack[0][:2]
# if time_attackGFX[-1] in [
# "A",
# "B",
# "C",
# "D",
# "E",
# "F",
# "G",
# "H",
# "I",
# ]:
# first_character = time_attackGFX[0]
# second_character = time_attackGFX[1]
# time_attackGFX = str(
# int(first_character, 16)
# + hex_dict.get(second_character, 0) / 10.0
# )
# time_attac_pic = path_pic + "\\24Sec_Red.png"
# else:
# time_attac_pic = path_pic + "\\24Sec_Orange.png"
# except IndexError:
# pass
# if timer_str[0] == " ":
# if timer_str == " 000":
# timer = "0.0"
# else:
# minites = timer_str[:2]
# seconds = timer_str[2:]
# timer = f"{int(minites)}:{seconds}".strip()
# elif timer_str[-1] == " ":
# seconds = timer_str[:2]
# milliseconds = timer_str[2:]
# timer = f"{int(seconds)}.{milliseconds}".strip()
# else:
# minites = timer_str[:2]
# seconds = timer_str[2:]
# timer = f"{int(minites)}:{seconds}".strip()
# print(
# f"Следующие 4 символа: {timer_str}, {timer}, {time_attackGFX}, Найдено: {found_value}, {data_str}_____"
# )
# with open(PATH, "r", encoding="utf-8") as f:
# new_data = json.load(f)
# new_data = new_data[0]
# new_data["timeGFX"] = timer
# new_data["time_attackGFX"] = time_attackGFX
# new_data["time_attac_pic"] = time_attac_pic
# if points1:
# new_data["points1"] = points1
# new_data["points2"] = points2
# new_data["quarter"] = quarter
# try:
# with open(PATH, "w", encoding="utf-8") as file:
# json.dump(
# [new_data], file, ensure_ascii=False, indent=4
# )
# except Exception:
# pass
else:
# In case nothing is coming down the serial interface
print(
"\rWaiting for serial input...",
end=" ",
flush=True,
)
# in case that the Serial Read or HTTP request fails
except Exception as e1:
print("error communicating...: " + str(e1))
logging.error("error communicating...: " + str(e1))
else:
print("Port Opening Failed... trying again in 5 seconds")
time.sleep(0.1)
ser.close()
except SerialException:
print("No port connected... trying again in 5 seconds")
time.sleep(0.1)

View File

@@ -0,0 +1,25 @@
start = "\xf8"
finish = "\r"
with open('megasport_new_5.txt', 'r') as file:
new_lines = []
current_line = ""
capturing = False
for line in file:
if start in line:
capturing = True
current_line = line[line.index(start):]
elif capturing:
if finish in line:
finish_idx = line.index(finish)
current_line += line[:finish_idx + len(finish)]
new_lines.append(current_line)
current_line = ""
capturing = False
else:
current_line += line
with open('new_log.txt', 'w') as new_file:
for line in new_lines:
new_file.write(line + '\n')