def generate_body_summary(self): """Generate body for email, including statistics.""" stat = StatAnalysis( initial_date=self.initial_date, until_date=self.until_date ) email_summary = ( '<p>//vault.thelensnola.org/realestate/search?d1={0}&d2={1}' + '</p>\n\n' + '<p>{2} sales recorded on {3} to {4}.</p>\n\n' + '<p>{5} records not published because of suspect data.</p>\n\n' + '<p>{6} records not published because location ' + 'could not be found.</p>\n\n' + '<p>High: ${7}</p>\n\n' + '<p>Low: ${8}</p>\n\n' ).format( ymd_to_mdy_slashes(self.initial_date), # 0 ymd_to_mdy_slashes(self.until_date), # 1 format(stat.count(), ','), # 2 ymd_to_full_date(self.initial_date), # 3 ymd_to_full_date(self.until_date), # 4 format(stat.detail_not_published(), ','), # 5 format(stat.location_not_published(), ','), # 6 stat.highest_amount(), # 7 stat.lowest_amount() # 8 ) return email_summary
def generate_subject(self): """Generate subject for email.""" subject = "Real Estate summary for" if self.initial_date == self.until_date: subject += " {}".format(ymd_to_full_date(self.initial_date)) else: subject += " {0} to {1}".format( ymd_to_full_date(self.initial_date, no_day=True), ymd_to_full_date(self.until_date, no_day=True)) return subject
def generate_subject(self): """Generate subject for email.""" subject = "Real Estate summary for" if self.initial_date == self.until_date: subject += " {}".format(ymd_to_full_date(self.initial_date)) else: subject += " {0} to {1}".format( ymd_to_full_date(self.initial_date, no_day=True), ymd_to_full_date(self.until_date, no_day=True) ) return subject
def test_ymd_to_full_date_no_ap_month_abbr(self): """Test ymd_to_full_date() with unabbreviated month.""" input = "2016-07-21" expected = "Thursday, July 21, 2016" actual = ymd_to_full_date(input) self.assertEqual(actual, expected)
def test_ymd_to_full_date_no_leading_zero(self): """Test ymd_to_full_date() with one-digit date.""" input = "2016-12-01" expected = "Thursday, Dec. 1, 2016" actual = ymd_to_full_date(input) self.assertEqual(actual, expected)
def test_ymd_to_full_date(self): """Test ymd_to_full_date().""" input = "2016-12-31" expected = "Saturday, Dec. 31, 2016" actual = ymd_to_full_date(input) self.assertEqual(actual, expected)
def test_ymd_to_full_date_none(self): """Test ymd_to_full_date() when input is None.""" input = None expected = "None" actual = ymd_to_full_date(input) self.assertEqual(actual, expected)
def test_ymd_to_full_date_slashes(self): """Test ymd_to_full_date() when input has slashes.""" input = "12/31/2016" expected = "Dec. 31, 2016" actual = ymd_to_full_date(input) self.assertEqual(actual, expected)
def test_ymd_to_full_date_no_day(self): """Test ymd_to_full_date() without day.""" input = "2016-12-31" expected = "Dec. 31, 2016" actual = ymd_to_full_date(input, no_day=True) self.assertEqual(actual, expected)
def get_sale(self, instrument_no): """TODO.""" data = {} data['update_date'] = self.get_last_updated_date() query = SESSION.query(Cleaned).filter( Cleaned.instrument_no == '%s' % (instrument_no)).filter( Cleaned.detail_publish.is_(True) # Only publish trusted data ).all() for row in query: row.amount = get_num_with_curr_sign(row.amount) row.document_date = ymd_to_full_date( (row.document_date).strftime('%Y-%m-%d'), no_day=True) # address = row.address # location_info = row.location_info data['assessor_publish'] = row.assessor_publish # newrows = query features = self.build_features_json(query) jsdata = {"type": "FeatureCollection", "features": features} SESSION.close() if len(query) == 0: return None, None, None else: return data, jsdata, query
def add_date_language(self, final_sentence): """ Add date language. Ex. ...between Feb. 10, 2014, and Feb. 12, 2014. """ if self.data['begin_date'] != '': if self.data['end_date'] != '': final_sentence += " between {0}, and {1},".format( ymd_to_full_date(self.data['begin_date'], no_day=True), ymd_to_full_date(self.data['end_date'], no_day=True)) else: final_sentence += " after {},".format( ymd_to_full_date(self.data['begin_date'], no_day=True)) elif self.data['end_date'] != '': final_sentence += " before {},".format( ymd_to_full_date(self.data['end_date'], no_day=True)) return final_sentence
def generate_body_summary(self): """Generate body for email, including statistics.""" stat = StatAnalysis(initial_date=self.initial_date, until_date=self.until_date) email_summary = ( '<p>//vault.thelensnola.org/realestate/search?d1={0}&d2={1}' + '</p>\n\n' + '<p>{2} sales recorded on {3} to {4}.</p>\n\n' + '<p>{5} records not published because of suspect data.</p>\n\n' + '<p>{6} records not published because location ' + 'could not be found.</p>\n\n' + '<p>High: ${7}</p>\n\n' + '<p>Low: ${8}</p>\n\n').format( ymd_to_mdy_slashes(self.initial_date), # 0 ymd_to_mdy_slashes(self.until_date), # 1 format(stat.count(), ','), # 2 ymd_to_full_date(self.initial_date), # 3 ymd_to_full_date(self.until_date), # 4 format(stat.detail_not_published(), ','), # 5 format(stat.location_not_published(), ','), # 6 stat.highest_amount(), # 7 stat.lowest_amount() # 8 ) return email_summary
def get_last_updated_date(self): """TODO.""" query = SESSION.query(Cleaned).filter( Cleaned.detail_publish.is_(True)).order_by( desc(Cleaned.document_recorded)).limit(1).all() log.info(query) updated_date = '' for row in query: updated_date = ymd_to_full_date( (row.document_recorded).strftime('%Y-%m-%d'), no_day=True) log.info(updated_date) SESSION.close() return updated_date
def get_search(self, request): """ GET call for /realestate/search. :param request: The request object(?). :returns: A data dict, SQL query result and JS data. """ data = self.parse_query_string(request) data = self.decode_data(data) data = self.convert_entries_to_db_friendly(data) data['update_date'] = self.get_last_updated_date() data['neighborhoods'] = self.get_neighborhoods() data = self.determine_pages(data) query = self.find_page_of_publishable_rows_fitting_criteria(data) for row in query: row.amount = get_num_with_curr_sign(row.amount) row.document_date = ymd_to_full_date( (row.document_date).strftime('%Y-%m-%d'), no_day=True) features = self.build_features_json(query) jsdata = {"type": "FeatureCollection", "features": features} data['results_css_display'] = 'none' if data['number_of_records'] == 0: data['current_page'] = 0 data['results_css_display'] = 'block' data = self.revert_entries(data) data['map_button_state'] = False data['results_language'] = ResultsLanguage(data).main() log.debug('data') return data, query, jsdata
def mapquery_db(self, data): """TODO.""" data['bounds'] = [ data['bounds']['_northEast']['lat'], data['bounds']['_northEast']['lng'], data['bounds']['_southWest']['lat'], data['bounds']['_southWest']['lng'] ] data['update_date'] = self.get_last_updated_date() log.debug('map_button_state') if data['map_button_state']: # map filtering is on query = self.filter_by_map(data) # TODO: was defined elsewhere else: # map filtering is off query = self.do_not_filter_by_map(data) for row in query: row.amount = get_num_with_curr_sign(row.amount) row.document_date = ymd_to_full_date( (row.document_date).strftime('%Y-%m-%d'), no_day=True) features = self.build_features_json(query) jsdata = {"type": "FeatureCollection", "features": features} if data['number_of_records'] == 0: data['current_page'] = 0 data['results_css_display'] = 'block' else: data['results_css_display'] = 'none' data = self.revert_entries(data) data['results_language'] = ResultsLanguage(data).main() log.debug('data returned:') log.debug(data) return data, query, jsdata