diff options
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 |