diff options
author | rusinthread <rusinthread@cock.li> | 2017-02-14 16:47:28 +0300 |
---|---|---|
committer | rusinthread <rusinthread@cock.li> | 2017-02-14 16:47:28 +0300 |
commit | 2bf675631511bec3cd7e41dd347523ef59715e0c (patch) | |
tree | 3fe2562f0c0fe4e04da73a520ac8cf0f1af3209a /data_lib.py | |
parent | ad2ed5d7dce466ad7f52ccfa4792c678820b3d89 (diff) |
add new lib
Diffstat (limited to 'data_lib.py')
-rw-r--r-- | data_lib.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/data_lib.py b/data_lib.py index 5bf468e..fea488f 100644 --- a/data_lib.py +++ b/data_lib.py @@ -13,7 +13,7 @@ def _data_sort_date(i): return int(time.mktime(datetime.datetime.strptime(i['date'], '%d/%m/%y').timetuple())) # sort: 'len', 'date' -def load_data(sort='len', sort_reverse=False): +def load_data(sort='len', sort_reverse=False, date=None, type=None): with open(os.path.join(CWD, "data.json")) as f: data = json.loads(f.read()) @@ -28,8 +28,14 @@ def load_data(sort='len', sort_reverse=False): else: raise Error("Unknown sort type " + str(sort)) + # filter by date data = sorted(data, key=sort_f, reverse=sort_reverse) + if date: + data = list(filter(lambda i: 'date' in i and i['date'] == date, data)) + + if type: + data = list(filter(lambda i: 'type' in i and i['type'] == type, data)) return data |