2021-09-16 20:07:18 +02:00
|
|
|
from datetime import datetime
|
2021-09-17 10:22:04 +02:00
|
|
|
from typing import Dict
|
|
|
|
import warnings
|
2021-09-16 20:07:18 +02:00
|
|
|
|
2021-09-16 15:27:35 +02:00
|
|
|
from config import MAX_LEN
|
|
|
|
|
|
|
|
|
2019-09-15 20:42:11 +02:00
|
|
|
def beautify(string):
|
|
|
|
return string.replace('_', ' ').replace('-', ' ').title()
|
|
|
|
|
2021-09-16 15:27:35 +02:00
|
|
|
|
2019-09-15 20:42:11 +02:00
|
|
|
def unbeautify(string):
|
|
|
|
return string.replace(' ', '-').lower()
|
|
|
|
|
2021-09-16 15:27:35 +02:00
|
|
|
|
2019-09-15 20:42:11 +02:00
|
|
|
def generate_short_title(title):
|
|
|
|
short_title = title or 'Untitled'
|
|
|
|
if len(title) >= MAX_LEN:
|
|
|
|
short_title = title[:MAX_LEN - len(' ... ')] + ' ... '
|
|
|
|
short_title = short_title.replace('$', '')
|
|
|
|
return short_title
|
2021-09-16 20:07:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
def get_week(d=datetime.today()):
|
2021-09-17 10:22:04 +02:00
|
|
|
return (int(d.strftime("%W")) + 52 - 5) % 52
|
|
|
|
|
|
|
|
|
|
|
|
def merge_dictionaries(main: Dict, fallback: Dict):
|
|
|
|
merged = main
|
|
|
|
for key in fallback.keys():
|
|
|
|
if key not in main.keys():
|
|
|
|
merged[key] = fallback[key]
|
|
|
|
elif type(fallback[key]) == dict:
|
|
|
|
if not type(merged[key]) == dict:
|
|
|
|
warnings.warn(
|
|
|
|
f"Main dictionary has invalid format. Replacing entry with key {key} with fallback value.")
|
|
|
|
merged[key] = fallback[key]
|
|
|
|
merged[key] = merge_dictionaries(merged[key], fallback[key])
|
|
|
|
return merged
|