from decimal import *
from pkg_resources import resource_filename
import json
+import re
import gettext
data_file = get_data_file(resulting_config)
write_latest_movements(data_file, resulting_config)
+def mov_filter(movs, filter):
+ return list(filter(lambda m: re.match(filter, m[DESCRIPTION_FIELD_NAME])))
+
+def filter_regex_movements(data_file, conf, filter):
+ movements = load_file(data_file)
+ ordered_movements = sort_movements(movements)
+ filtered_movements = mov_filter(ordered_movements, filter)
+ for movement in filtered_movements:
+ formatted_movement = format_movement(ordered_movements[i])
+ print(formatted_movement)
+
+def filter_movements():
+ """Writes the latest movements that match a filter formatted.
+
+ Called by money-filter
+
+ """
+ filter = read_filter()
+ default_config = default_configuration()
+ resulting_config = None
+ if file_exists(CONFIG_FILE_LOCATION):
+ config_from_file = configuration_from_file(CONFIG_FILE_LOCATION)
+ resulting_config = override_default_configuration(
+ default_config, config_from_file)
+ else:
+ resulting_config = default_config
+ data_file = get_data_file(resulting_config)
+ filter_regex_movements(data_file, resulting_config, filter)
def override_default_configuration(default_conf, other_conf):
result_conf = {DATA_FILE_NAME: default_conf[DATA_FILE_NAME]}
self.assertEqual(res[2]['prog'], 3)
self.assertEqual(res[3]['prog'], 4)
+ def test_mov_filter(self):
+ m = {
+ money.TYPE_FIELD_NAME: '-',
+ money.VALUE_FIELD_NAME: '100',
+ money.DATE_FIELD_NAME: '18/04/2017',
+ money.HOUR_FIELD_NAME: '00:01',
+ money.DESCRIPTION_FIELD_NAME: 'test',
+ }
+ ms = [m]
+ res = money.mov_filter(ms, 't')
+ self.assertEqual(len(res), 1)
+
def create_test_movement(date, hour, prog):
return {