Jelajahi Sumber

mark search results as gone

Martin 8 tahun lalu
induk
melakukan
980685ab9c
2 mengubah file dengan 17 tambahan dan 3 penghapusan
  1. 2 2
      db_schema.py
  2. 15 1
      monitor.py

+ 2 - 2
db_schema.py

@@ -19,8 +19,8 @@ SCHEMA_STATEMENTS = [
         id integer not null primary key,
         time datetime not null,
         property_id integer not null,
-        price integer not null,
-        raw_json text not null
+        price varchar(255) not null,
+        raw_json text
     )
     ''',
 

+ 15 - 1
monitor.py

@@ -249,7 +249,21 @@ def search(conn, locality_id):
         
         page += 1
 
-    gone = set(known_prices.keys()).difference(seen_properties)
+    gone = {pid for pid, price in known_prices.items() if price != 'GONE'}.difference(seen_properties)
+
+    if gone:
+        stmt = 'insert into search_results (search_locality_id, time, property_id, price) VALUES'
+        params = []
+        for property_id in gone:
+            stmt += ' (?, ?, ?, ?),' 
+            params.extend([
+                locality_id,
+                _now(),
+                property_id,
+                'GONE',
+            ])
+        
+        conn.execute(stmt[:-1], *params)
 
     print('Search complete. %i records fetched; %i new records added; %i records modified; %i records marked as gone.' % (len(seen_properties), added, modified, len(gone)))