shop-rumine-api/utils.py

26 lines
759 B
Python
Raw Normal View History

2024-02-25 14:55:37 +01:00
import yaml
2024-02-26 02:40:08 +01:00
import datetime
2024-02-25 14:55:37 +01:00
def read_config(config_file):
with open(config_file, 'r') as file:
config = yaml.safe_load(file)
return config
2024-02-26 02:40:08 +01:00
def get_parameters() -> dict:
2024-02-25 14:55:37 +01:00
parameters = {}
config = read_config('config.yml')
for key, value in config.items():
if isinstance(value, dict):
for sub_key, sub_value in value.items():
parameters[f'{key}_{sub_key}'] = sub_value
else:
parameters[key] = value
return parameters
2024-02-26 02:40:08 +01:00
def get_unix_timestamp_after_days(days: int) -> int:
return int((datetime.datetime.now() + datetime.timedelta(days=days)).timestamp()) if days != 0 else 0
def get_uts(timestamp: int) -> int:
return datetime.datetime.utcfromtimestamp(timestamp)