Browse Source

Reduce logs verbosity

Gautier P 10 months ago
parent
commit
582a868a1d
2 changed files with 15 additions and 43 deletions
  1. 8
    26
      flatisfy/cmds.py
  2. 7
    17
      flatisfy/filters/__init__.py

+ 8
- 26
flatisfy/cmds.py View File

@@ -23,9 +23,7 @@ import time
23 23
 LOGGER = logging.getLogger(__name__)
24 24
 
25 25
 
26
-def filter_flats_list(
27
-    config, constraint_name, flats_list, fetch_details=True, past_flats=None
28
-):
26
+def filter_flats_list(config, constraint_name, flats_list, fetch_details=True, past_flats=None):
29 27
     """
30 28
     Filter the available flats list. Then, filter it according to criteria.
31 29
 
@@ -69,7 +67,7 @@ def filter_flats_list(
69 67
 
70 68
             use_cache = past_ids.get(flat["id"])
71 69
             if use_cache:
72
-                LOGGER.info("Skipping details download for %s.", flat["id"])
70
+                LOGGER.debug("Skipping details download for %s.", flat["id"])
73 71
                 details = use_cache
74 72
             else:
75 73
                 details = fetch.fetch_details(config, flat["id"])
@@ -82,32 +80,22 @@ def filter_flats_list(
82 80
     # Do a second pass to consolidate all the infos we found and make use of
83 81
     # additional infos
84 82
     if config["passes"] > 1:
85
-        second_pass_result = flatisfy.filters.second_pass(
86
-            first_pass_result["new"], constraint, config
87
-        )
83
+        second_pass_result = flatisfy.filters.second_pass(first_pass_result["new"], constraint, config)
88 84
     else:
89 85
         second_pass_result["new"] = first_pass_result["new"]
90 86
 
91 87
     # Do a third pass to deduplicate better
92 88
     if config["passes"] > 2:
93
-        third_pass_result = flatisfy.filters.third_pass(
94
-            second_pass_result["new"], config
95
-        )
89
+        third_pass_result = flatisfy.filters.third_pass(second_pass_result["new"], config)
96 90
     else:
97 91
         third_pass_result["new"] = second_pass_result["new"]
98 92
 
99 93
     return {
100 94
         "new": third_pass_result["new"],
101 95
         "duplicate": (
102
-            first_pass_result["duplicate"]
103
-            + second_pass_result["duplicate"]
104
-            + third_pass_result["duplicate"]
105
-        ),
106
-        "ignored": (
107
-            first_pass_result["ignored"]
108
-            + second_pass_result["ignored"]
109
-            + third_pass_result["ignored"]
96
+            first_pass_result["duplicate"] + second_pass_result["duplicate"] + third_pass_result["duplicate"]
110 97
         ),
98
+        "ignored": (first_pass_result["ignored"] + second_pass_result["ignored"] + third_pass_result["ignored"]),
111 99
     }
112 100
 
113 101
 
@@ -178,10 +166,7 @@ def import_and_filter(config, load_from_db=False, new_only=False):
178 166
 
179 167
         for status, flats_list in flatten_flats_by_status.items():
180 168
             # Build SQLAlchemy Flat model objects for every available flat
181
-            flats_objects = {
182
-                flat_dict["id"]: flat_model.Flat.from_dict(flat_dict)
183
-                for flat_dict in flats_list
184
-            }
169
+            flats_objects = {flat_dict["id"]: flat_model.Flat.from_dict(flat_dict) for flat_dict in flats_list}
185 170
 
186 171
             if flats_objects:
187 172
                 # If there are some flats, try to merge them with the ones in
@@ -266,8 +251,5 @@ def serve(config):
266 251
         # standard logging
267 252
         server = web_app.QuietWSGIRefServer
268 253
 
269
-    print(
270
-        "Launching web viewer running on http://%s:%s"
271
-        % (config["host"], config["port"])
272
-    )
254
+    print("Launching web viewer running on http://%s:%s" % (config["host"], config["port"]))
273 255
     app.run(host=config["host"], port=config["port"], server=server)

+ 7
- 17
flatisfy/filters/__init__.py View File

@@ -37,15 +37,13 @@ def refine_with_housing_criteria(flats_list, constraint):
37 37
         # Check postal code
38 38
         postal_code = flat["flatisfy"].get("postal_code", None)
39 39
         if postal_code and postal_code not in constraint["postal_codes"]:
40
-            LOGGER.info("Postal code for flat %s is out of range.", flat["id"])
40
+            LOGGER.info("Postal code %s for flat %s is out of range.", postal_code, flat["id"])
41 41
             is_ok[i] = is_ok[i] and False
42 42
 
43 43
         # Check time_to
44 44
         for place_name, time in flat["flatisfy"].get("time_to", {}).items():
45 45
             time = time["time"]
46
-            is_within_interval = tools.is_within_interval(
47
-                time, *(constraint["time_to"][place_name]["time"])
48
-            )
46
+            is_within_interval = tools.is_within_interval(time, *(constraint["time_to"][place_name]["time"]))
49 47
             if not is_within_interval:
50 48
                 LOGGER.info(
51 49
                     "Flat %s is too far from place %s: %ds.",
@@ -58,12 +56,10 @@ def refine_with_housing_criteria(flats_list, constraint):
58 56
         # Check other fields
59 57
         for field in ["area", "cost", "rooms", "bedrooms"]:
60 58
             interval = constraint[field]
61
-            is_within_interval = tools.is_within_interval(
62
-                flat.get(field, None), *interval
63
-            )
59
+            is_within_interval = tools.is_within_interval(flat.get(field, None), *interval)
64 60
             if not is_within_interval:
65 61
                 LOGGER.info(
66
-                    "%s for flat %s is out of range.", field.capitalize(), flat["id"]
62
+                    "%s %s for flat %s is out of range.", field.capitalize(), str(flat.get(field, None)), flat["id"]
67 63
                 )
68 64
             is_ok[i] = is_ok[i] and is_within_interval
69 65
 
@@ -95,9 +91,7 @@ def refine_with_details_criteria(flats_list, constraint):
95 91
 
96 92
     for i, flat in enumerate(flats_list):
97 93
         # Check number of pictures
98
-        has_enough_photos = tools.is_within_interval(
99
-            len(flat.get("photos", [])), constraint["minimum_nb_photos"], None
100
-        )
94
+        has_enough_photos = tools.is_within_interval(len(flat.get("photos", [])), constraint["minimum_nb_photos"], None)
101 95
         if not has_enough_photos:
102 96
             LOGGER.info(
103 97
                 "Flat %s only has %d photos, it should have at least %d.",
@@ -148,16 +142,12 @@ def first_pass(flats_list, constraint, config):
148 142
 
149 143
     # Handle duplicates based on ids
150 144
     # Just remove them (no merge) as they should be the exact same object.
151
-    flats_list, _ = duplicates.detect(
152
-        flats_list, key="id", merge=False, should_intersect=False
153
-    )
145
+    flats_list, _ = duplicates.detect(flats_list, key="id", merge=False, should_intersect=False)
154 146
     # Also merge duplicates based on urls (these may come from different
155 147
     # flatboob backends)
156 148
     # This is especially useful as some websites such as entreparticuliers
157 149
     # contains a lot of leboncoin housings posts.
158
-    flats_list, duplicates_by_urls = duplicates.detect(
159
-        flats_list, key="urls", merge=True, should_intersect=True
160
-    )
150
+    flats_list, duplicates_by_urls = duplicates.detect(flats_list, key="urls", merge=True, should_intersect=True)
161 151
 
162 152
     # Guess the postal codes
163 153
     flats_list = metadata.guess_postal_code(flats_list, constraint, config)