def search(params={}, batching=True, context=None, config=None): """Search for listings.""" if config is None: config = {} settings = get_settings(context=context) search_params = {"sort_on": "last_activated_date", "reverse": "1"} listing_types = set(config.get("listing_type", ())) if listing_types: # Available Listing Types are restricted. search_listing_types = params.get("listing_type", None) if search_listing_types: search_listing_types = set(search_listing_types.split(",")) listing_types = listing_types.intersection(search_listing_types) params["listing_type"] = ",".join(listing_types) agency_listings = params.pop("agency_listings", False) if agency_listings is True: search_params["agency_id"] = settings.get("agency_id", None) search_params.update(params) base_url = settings.get("mls_site", None) api_key = settings.get("mls_key", None) batch = None results = [] resource = ListingResource(base_url, api_key=api_key) try: results, batch = resource.search(search_params) except MLSError, e: logger.warn(e)
def _retrieveCategory(self): """do the actual work and try to retrieve the feed""" if self.category is not None: self._last_update_time_in_minutes = time.time() / 60 self._last_update_time = DateTime() settings = get_settings(context=self.context) base_url = settings.get('mls_site', None) api_key = settings.get('mls_key', None) debug = api.env.debug_mode resource = ListingResource(base_url, api_key=api_key, debug=debug) results = [] try: results = resource.category(self.category, self.language) except MLSError as e: self._loaded = True # we tried at least but have a failed load self._failed = True logger.warn(e) return False self._items = results self._loaded = True self._failed = False return True self._loaded = True self._failed = True # no url set means failed return False # no url set, although that should not really happen
def listing_details(listing_id, lang=None, context=None): """Return detail information for a listing.""" settings = get_settings(context=context) base_url = settings.get("mls_site", None) api_key = settings.get("mls_key", None) resource = ListingResource(base_url, api_key=api_key) try: listing = resource.get(listing_id, lang=lang) except MLSError, e: logger.warn(e) return None
def test_view_types(self): resource = 'view_types' responses.add( responses.GET, utils.get_url(self.URL, resource), body=utils.load_fixture('category_view_types_en.json') ) client = ListingResource(self.BASE_URL) category = client.category(resource) expected = [ ('beach_view', 'Beach View'), ] assert category == expected
def test_listing_types(self): resource = 'listing_types' responses.add( responses.GET, utils.get_url(self.URL, resource), body=utils.load_fixture('category_listing_types_en.json') ) client = ListingResource(self.BASE_URL) category = client.category(resource) expected = [ ('ll', 'Land Listing'), ('rl', 'Residential Lease'), ('rs', 'Residential Sale'), ] assert category == expected
def search(params={}, batching=True, context=None, config=None): """Search for listings.""" if config is None: config = {} settings = get_settings(context=context) search_params = { 'sort_on': 'last_activated_date', 'reverse': '1', } if config.get('show_unverified', False): search_params['apiowner'] = settings.get('agency_id') listing_types = set(config.get('listing_type', ())) if listing_types: # Available Listing Types are restricted. search_listing_types = params.get('listing_type', None) if search_listing_types: search_listing_types = set(search_listing_types.split(',')) listing_types = listing_types.intersection(search_listing_types) params['listing_type'] = ','.join(listing_types) agency_listings = params.pop('agency_listings', False) agency_priority = params.get('agency_priority', False) if agency_listings is True or agency_priority is True: agency_id = params.pop('overriding_agency_id', None) if not agency_id: agency_id = settings.get('agency_id', None) agency_id = agency_id.replace(' ', '') search_params['agency_id'] = agency_id search_params.update(params) base_url = settings.get('mls_site', None) api_key = settings.get('mls_key', None) batch = None results = [] debug = api.env.debug_mode resource = ListingResource(base_url, api_key=api_key, debug=debug) try: results, batch = resource.search(search_params) except MLSError as e: logger.warn(e) if batching: return results, batch return results
def _retrieveCategory(self): """do the actual work and try to retrieve the feed""" if self.category is not None: self._last_update_time_in_minutes = time.time() / 60 self._last_update_time = DateTime() settings = get_settings(context=self.context) base_url = settings.get("mls_site", None) api_key = settings.get("mls_key", None) resource = ListingResource(base_url, api_key=api_key) results = [] try: results = resource.category(self.category, self.language) except MLSError, e: self._loaded = True # we tried at least but have a failed load self._failed = True logger.warn(e) return False self._items = results self._loaded = True self._failed = False return True
def listing_details(listing_id, lang=None, context=None): """Return detail information for a listing.""" settings = get_settings(context=context) base_url = settings.get('mls_site', None) api_key = settings.get('mls_key', None) debug = api.env.debug_mode config = get_configs(context=context, merged=True) params = {} if config.get('show_unverified', False): params['apiowner'] = settings.get('agency_id') params['show_unverified'] = True if config.get('show_unverified_only', False): params['show_unverified_only'] = True resource = ListingResource(base_url, api_key=api_key, debug=debug) try: listing = resource.get(listing_id, lang=lang, params=params) except MLSError as e: logger.warn(e) return None listing = listing.get('listing', None) if listing is not None: agent = copy.deepcopy(listing.get('contact', {}).get('agent')) listing['original_agent'] = agent return listing