add seconds from now offset time prompt

This commit is contained in:
Robin Müller 2023-02-17 18:55:41 +01:00
parent d97eb7334b
commit c9f35c3e5c
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC

View File

@ -49,7 +49,10 @@ def pack_tm_store_commands(p: ServiceProviderParams):
app_data.extend(struct.pack("!I", end_stamp))
q.add_log_cmd(Info.DELETE_UP_TO)
q.add_log_cmd(f"Selected Store: {obj_id}")
q.add_log_cmd(f"Deletion up to time {delete_up_to_time}")
q.add_log_cmd(
f"Deletion up to time "
f"{datetime.datetime.fromtimestamp(end_stamp, tz=datetime.timezone.utc)}"
)
print(
PusTelecommand(
service=15, subservice=Subservice.DELETE_UP_TO, app_data=app_data
@ -80,16 +83,53 @@ STORE_DICT = {
}
TIME_INPUT_DICT = {
1: "Full manual input with dateutil.parser.parse",
2: "Offset from now in seconds",
}
def time_prompt() -> datetime.datetime:
print("Available time input types: ")
for k, v in TIME_INPUT_DICT.items():
print(f" {k}: {v}")
while True:
time_input_key = int(input("Please specify a time input type by key: "))
if time_input_key not in TIME_INPUT_DICT.keys():
_LOGGER.warning("Invalid key, try again")
continue
break
if time_input_key == 1:
return time_prompt_fully_manually()
elif time_input_key == 2:
return time_prompt_offset_from_now()
def time_prompt_fully_manually() -> datetime.datetime:
# TODO: Add support for offset from now in seconds
delete_up_to_time = parse(
time = parse(
input(
"Please enter delete end time in any format supported by dateutil.parser.parse\n"
"Please enter the time in any format supported by dateutil.parser.parse\n"
"Recommended format: UTC ISO format YYYY-MM-DDThh:mm:ssZ: "
)
)
print(f"Parsed timestamp: {delete_up_to_time}")
return delete_up_to_time
print(f"Parsed timestamp: {time}")
return time
def time_prompt_offset_from_now() -> datetime.datetime:
seconds_offset = math.floor(
float(
input(
"Please enter the time as a offset from now in seconds. Negative offset is allowed: "
)
)
)
time_now_with_offset = datetime.datetime.now(
tz=datetime.timezone.utc
) + datetime.timedelta(seconds=seconds_offset)
print(f"Absolute resulting time: {time_now_with_offset}")
return time_now_with_offset
def store_select_prompt() -> (ObjectIdU32, str):
@ -98,7 +138,7 @@ def store_select_prompt() -> (ObjectIdU32, str):
idx_to_obj_id = dict()
for idx, (k, v) in enumerate(STORE_DICT.items()):
idx_to_obj_id.update({idx: (k, v)})
print(f"{idx}: {v}")
print(f" {idx}: {v}")
while True:
target_index = int(
input("Please enter the target store for the TM store transaction: ")