diff --git a/flatisfy/cmds.py b/flatisfy/cmds.py index 8d14d27..c48e5c8 100644 --- a/flatisfy/cmds.py +++ b/flatisfy/cmds.py @@ -155,6 +155,11 @@ def import_and_filter(config, load_from_db=False): flatten_flats_by_status[status].extend(flats_list) with get_session() as session: + # Set is_expired to true for all existing flats. + # This will be set back to false if we find them during importing. + for flat in session.query(flat_model.Flat).all(): + flat.is_expired = True; + for status, flats_list in flatten_flats_by_status.items(): # Build SQLAlchemy Flat model objects for every available flat flats_objects = { @@ -178,6 +183,10 @@ def import_and_filter(config, load_from_db=False): ) else: flat_object.status = each.status + + # Every flat we fetched isn't expired + flat_object.is_expired = False + # For each flat already in the db, merge it (UPDATE) # instead of adding it session.merge(flats_objects.pop(each.id)) diff --git a/flatisfy/models/flat.py b/flatisfy/models/flat.py index 7e3c3c3..fe4c0d0 100644 --- a/flatisfy/models/flat.py +++ b/flatisfy/models/flat.py @@ -11,7 +11,7 @@ import enum import arrow from sqlalchemy import ( - Column, DateTime, Enum, Float, SmallInteger, String, Text, inspect + Boolean, Column, DateTime, Enum, Float, SmallInteger, String, Text, inspect ) from sqlalchemy.orm import validates @@ -83,6 +83,7 @@ class Flat(BASE): merged_ids = Column(MagicJSON) notes = Column(Text) notation = Column(SmallInteger, default=0) + is_expired = Column(Boolean, default=False) # Flatisfy data # TODO: Should be in another table with relationships