def get_last_from(self, provider) -> Optional[AdvertisedProperty]:
     from_provider = sorted(
         filter(lambda d: d['provided_by'] == provider,
                self._repo.values()),
         key=lambda d: d['entered'],
         reverse=True,
     )
     if not from_provider:
         return None
     return AdvertisedProperty(**from_provider[0])
 def list_with_similar_address(
         self,
         address: str,
         similarity_threshold: float = 0.5) -> List[AdvertisedProperty]:
     # TODO proper distance
     address = address.lower()
     return list(
         map(
             lambda d: AdvertisedProperty(**d),
             filter(lambda d: address in d['address'].lower(),
                    self._repo.values())))
예제 #3
0
def mock_advertised(url):
    return AdvertisedProperty(
        url=url,
        address='Some nice address in Dublin',
        price=1200,
        provided_by='test',
        entered=datetime(2018, 9, 1, 19, 32, 10),
        flagged=False,
        sent_email=True,
        ok=True,
    )
예제 #4
0
def create_advertised_5():
    return AdvertisedProperty(
        url='http://somewhere.nice.location',
        address='XD 1',
        price=1200,
        provided_by='daft',
        entered=datetime(2018, 9, 1, 19, 32, 10),
        flagged=True,
        sent_email=False,
        ok=False,
    )
예제 #5
0
def create_advertised_3():
    return AdvertisedProperty(
        url='http://somewhere.nowhere',
        address='Ehhh 1',
        price=1400,
        provided_by='let',
        entered=datetime(2018, 9, 2, 18, 32, 10),
        flagged=True,
        sent_email=True,
        ok=True,
    )
예제 #6
0
def create_advertised_2():
    return AdvertisedProperty(
        url='http://ehh.nice.location',
        address='Sandyford Road 3',
        price=1400,
        provided_by='rent',
        entered=datetime(2018, 9, 1, 19, 32, 45),
        flagged=False,
        sent_email=True,
        ok=True,
    )
예제 #7
0
 def _object_model_from_parsed(
     self,
     parsed_accommodation: ParsedAccommodation,
     report_row: Optional[int] = None,
     sent_email: bool = False,
     is_ok: bool = True,
     need_verify: bool = False,
 ):
     return AdvertisedProperty(
         url=parsed_accommodation.url,
         address=parsed_accommodation.address,
         ok=is_ok,
         price=parsed_accommodation.price,
         flagged=need_verify,
         sent_email=sent_email,
         row=report_row,
         entered=parsed_accommodation.entered,
         provided_by=parsed_accommodation.provider,
     )
 def list_with_url(self, url: str) -> List[AdvertisedProperty]:
     return list(
         map(lambda d: AdvertisedProperty(**d),
             filter(lambda d: d['url'] == url, self._repo.values())))
 def list_ok(self):
     return list(
         map(lambda d: AdvertisedProperty(**d),
             filter(lambda d: d['ok'], self._repo.values())))
 def list_all(self) -> List[AdvertisedProperty]:
     return list(map(lambda d: AdvertisedProperty(**d),
                     self._repo.values()))
 def list_flagged(self) -> List[AdvertisedProperty]:
     return list(
         map(lambda d: AdvertisedProperty(**d),
             filter(lambda d: d['flagged'], self._repo.values())))
    def get(self, property_id: int) -> Optional[AdvertisedProperty]:
        stored_dict = self._repo.get(property_id)

        if stored_dict:
            return AdvertisedProperty(**stored_dict)
        return stored_dict
    def save(self, advertised_property: AdvertisedProperty):
        self._last_id = self._last_id + 1

        advertised_property.property_id = self._last_id
        self._repo[self._last_id] = self._property_to_dict(advertised_property)
예제 #14
0
 def save(self, advertised_property: AdvertisedProperty):
     insert = self.properties.insert().values(
         **self._property_to_dict(advertised_property), )
     result = self.session.execute(insert)
     advertised_property.property_id = result.inserted_primary_key[0]
예제 #15
0
 def _row_to_obj(self, row: tuple) -> AdvertisedProperty:
     return AdvertisedProperty(**dict(zip(self.properties_columns, row)))