This repository has been archived on 2024-10-27. You can view files and clone it, but cannot push or open issues or pull requests.
2023-08-29 13:46:41 -06:00
|
|
|
import json
|
2023-08-24 18:59:52 -06:00
|
|
|
from collections import OrderedDict
|
2023-08-21 21:28:52 -06:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
|
|
def resolve_path(*p: str):
|
|
|
|
return Path(*p).expanduser().resolve().absolute()
|
2023-08-22 20:28:41 -06:00
|
|
|
|
|
|
|
|
|
|
|
def safe_list_get(l, idx, default):
|
|
|
|
"""
|
|
|
|
https://stackoverflow.com/a/5125636
|
|
|
|
:param l:
|
|
|
|
:param idx:
|
|
|
|
:param default:
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
return l[idx]
|
|
|
|
except IndexError:
|
|
|
|
return default
|
2023-08-24 18:59:52 -06:00
|
|
|
|
|
|
|
|
|
|
|
def deep_sort(obj):
|
|
|
|
"""
|
|
|
|
https://stackoverflow.com/a/59218649
|
|
|
|
:param obj:
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
if isinstance(obj, dict):
|
|
|
|
obj = OrderedDict(sorted(obj.items()))
|
|
|
|
for k, v in obj.items():
|
|
|
|
if isinstance(v, dict) or isinstance(v, list):
|
|
|
|
obj[k] = deep_sort(v)
|
|
|
|
|
|
|
|
if isinstance(obj, list):
|
|
|
|
for i, v in enumerate(obj):
|
|
|
|
if isinstance(v, dict) or isinstance(v, list):
|
|
|
|
obj[i] = deep_sort(v)
|
|
|
|
obj = sorted(obj, key=lambda x: json.dumps(x))
|
|
|
|
|
|
|
|
return obj
|
2023-08-29 13:46:41 -06:00
|
|
|
|
|
|
|
|
|
|
|
def indefinite_article(word):
|
|
|
|
if word[0].lower() in 'aeiou':
|
|
|
|
return 'an'
|
|
|
|
else:
|
|
|
|
return 'a'
|