Move parse.py to library repository
This commit is contained in:
1 parent
92cfe365f4
commit
dcbd80e244
3 files changed
+2
-277
No files matched your search
+1
-28
@@ -12,34 +12,7 @@ from datetime import datetime
|
||||
|
||||
if not sys.version_info >= (3, 6):
|
||||
raise Exception("Python 3.6 or higher is required!")
|
||||
|
||||
# Byte conversions
|
||||
def bytes_to_string(data):
|
||||
return data.decode('ascii').replace('\x00', ' ').strip()
|
||||
|
||||
def bytes_to_hex(data, chunkify = False):
|
||||
output = data.hex().upper()
|
||||
return " ".join((output[0+i:2+i] for i in range(0, len(output), 2))) if chunkify else output
|
||||
|
||||
def bytes_to_int(data):
|
||||
return int.from_bytes(data, 'little')
|
||||
|
||||
def bytes_to_float(data):
|
||||
return struct.unpack('<f', data)[0]
|
||||
|
||||
def bytes_to_date(data):
|
||||
string = bytes_to_string(data)
|
||||
parts = string.split("_")
|
||||
if len(parts) < 5:
|
||||
return string # Not a date we can process, if it's a date at all
|
||||
return datetime(
|
||||
year=int(parts[0]),
|
||||
month=int(parts[1]),
|
||||
day=int(parts[2]),
|
||||
hour=int(parts[3]),
|
||||
minute=int(parts[4])
|
||||
)
|
||||
|
||||
|
||||
#Some keys come surrounded in terminal color codes such as "[32m63654db94d97[0m"
|
||||
#We need to remove these
|
||||
def strip_color_codes(input_string):
|
||||
|
||||
Reference in new issue
Block a user