def find_matches(cls): """ Find all matches inside yet unsearched listings """ # find product instances in listings profiler = Profiler() for listing in Listing.get_all(): for edition in PlatformEdition.get_all(): cls.search_for_matches(listing, edition) for platform in Platform.get_all(): cls.search_for_matches(listing, platform)
def generate_message_text(self): message_text_matches = '' message_text_matches = message_text_matches + 'PLATFORMS & EDITIONS\n\n' pp.pprint(Listing.registry) for platform in Platform.get_all(): if platform.id in self.platform_editions or ( self.platforms and platform.id in self.platforms): message_text_per_platform = '' # ----- Platform Name ----- message_text_per_platform = message_text_per_platform + '----- ' + platform.name + ' -----\n' if self.platform_editions.get(platform.id): for edition_id in self.platform_editions.get(platform.id): edition = PlatformEdition.get_by_id(edition_id) edition_referencial_name = edition.referencial_name() message_text_per_platform = message_text_per_platform + edition_referencial_name + '\n' if Mailer.pe_presences_per_pe.get(edition.id): for listing_id in Mailer.pe_presences_per_pe.get( edition.id): listing = Listing.get_by_id(listing_id) # listing title message_text_per_platform = message_text_per_platform + '\t' + listing.title + '\n' # listing price if listing.price is None: message_text_per_platform = message_text_per_platform + '\t' + '(price not listed)' + '\n' else: message_text_per_platform = message_text_per_platform + '\t' + listing.price + '\n' # listing link message_text_per_platform = message_text_per_platform + '\t' + listing.url + '\n' # listing datetime message_text_per_platform = message_text_per_platform + '\t' + str( listing.date_posted) + '\n' # blank line message_text_per_platform = message_text_per_platform + '\t' + '\n' message_text_per_platform = message_text_per_platform + '\n' message_text_matches = message_text_matches + message_text_per_platform return message_text_matches
def generate_message_html(self): message_text_matches = '' products_matched_ct = 0 platforms_and_editions_category_title = '<h2>PLATFORMS & EDITIONS</h2>\n\n' message_text_all_platforms = '' for platform in Platform.get_all(): message_text_this_platform = '' if platform.id in self.platform_editions or ( self.platforms and platform.id in self.platforms): # Platform Name this_platform_name = f'\n<h3>{platform.name}</h3>' message_text_this_platform_general = '' message_text_this_platform_list = '' platform_general_list_start = '\n<ul style="padding: 0; list-style: none;">' if self.platform_presences_per_platform.get(platform.id): listing_ct = 0 for listing_id in self.platform_presences_per_platform.get( platform.id): listing = Listing.get_by_id(listing_id) if listing is not None: listing_ct += 1 match = Match.get_by_info(listing, platform) message_text_this_platform_list = message_text_this_platform_list + Mailer.create_listing_html( match, listing_ct) platform_general_list_end = '\n</ul>' if len(message_text_this_platform_list) > 0: message_text_this_platform_general = message_text_this_platform_general + f"""{platform_general_list_start}\n{message_text_this_platform_list}\n{platform_general_list_end}""" message_text_all_editions = '' if self.platform_editions.get(platform.id): for edition_id in self.platform_editions.get(platform.id): edition = PlatformEdition.get_by_id(edition_id) edition_referencial_name = edition.referencial_name() message_text_this_edition = '' this_edition_name = f'\n<h4>{edition_referencial_name}</h4>' message_text_this_edition_listings = '' if Mailer.pe_presences_per_pe.get(edition.id): listing_ct = 0 editions_list_start = '\n<ul style="padding: 0; list-style: none;">' for listing_id in Mailer.pe_presences_per_pe.get( edition.id): listing = Listing.get_by_id(listing_id) if listing is not None: listing_ct += 1 match = Match.get_by_info(listing, edition) message_text_this_edition_listings = message_text_this_edition_listings + Mailer.create_listing_html( match, listing_ct) editions_list_end = '\n</ul>' if len(message_text_this_edition_listings) > 0: products_matched_ct += 1 # add edition title message_text_this_edition = message_text_this_edition + this_edition_name # add edition listings message_text_this_edition = message_text_this_edition + editions_list_start + message_text_this_edition_listings + editions_list_end if len(message_text_this_edition) > 0: # add edition message text message_text_all_editions = message_text_all_editions + message_text_this_edition if len(message_text_all_editions) > 0 or len( message_text_this_platform_general) > 0: # add platform title message_text_this_platform = message_text_this_platform + this_platform_name if len(message_text_this_platform_general) > 0: products_matched_ct += 1 general_platform_matches_title = f'\n<h4>General</h4>' # add platform generic message text message_text_this_platform = message_text_this_platform + general_platform_matches_title + message_text_this_platform_general if len(message_text_all_editions) > 0: # add platform editions message text message_text_this_platform = message_text_this_platform + message_text_all_editions if len(message_text_this_platform) > 0: # add platform editions message text message_text_all_platforms = message_text_all_platforms + message_text_this_platform if len(message_text_all_platforms) > 0: # add platform & edition category title to mail message message_text_matches = message_text_matches + platforms_and_editions_category_title # add platform & edition category content to mail message message_text_matches = message_text_matches + message_text_all_platforms return message_text_matches, products_matched_ct