diff options
author | Frederick Yin <fkfd@fkfd.me> | 2022-02-01 12:43:25 +0800 |
---|---|---|
committer | Frederick Yin <fkfd@fkfd.me> | 2022-02-01 12:43:25 +0800 |
commit | 0e47cf9a8d06e896c5197cb28cb5a2a518d255d1 (patch) | |
tree | 22a0267dbfe204038aaac48d8596d436b5d56291 /jimbrella/utils.py | |
parent | 444966b2ff4a04374856d3a6759bef9e9f451c03 (diff) |
SQLite in favor of CSV database
Deprecate csv database format, move around some methods
Diffstat (limited to 'jimbrella/utils.py')
-rw-r--r-- | jimbrella/utils.py | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/jimbrella/utils.py b/jimbrella/utils.py index ce57bf9..31fafbc 100644 --- a/jimbrella/utils.py +++ b/jimbrella/utils.py @@ -21,22 +21,12 @@ def human_timedelta(delta: timedelta) -> str: return days + f"{hours:0>2}:{minutes:0>2}" # zero-pad to two digits -class UTCPlus8(tzinfo): - def __init__(self): - super().__init__() - - def utcoffset(self, dt): - return timedelta(hours=8) - - def dst(self, dt): - return timedelta(0) - - def tzname(self, dt): - return "+8:00" - - -utc_plus_8 = UTCPlus8() - - -def local_now(): - return datetime.now(tz=utc_plus_8) +def group_by_key(data: list, key: str) -> dict: + """Groups a list of dicts by the value of their `key` into a dict of lists of dicts.""" + keys = set([item[key] for item in data]) + # initiate a dict with `keys` as keys and [] as values + groups = dict.fromkeys(keys, []) + for k in keys: + groups[k] = [item for item in data if item[key] == k] + + return groups |