def database_row_to_elasticsearch_doc(row, schema): provider = row[schema['provider']] source = row[schema['source']] extension = Image.get_extension(row[schema['url']]) height = row[schema['height']] width = row[schema['width']] meta = row[schema['meta_data']] return Image( _id=row[schema['id']], id=row[schema['id']], title=row[schema['title']], identifier=row[schema['identifier']], creator=row[schema['creator']], creator_url=row[schema['creator_url']], tags=Image.parse_detailed_tags(row[schema['tags']]), created_on=row[schema['created_on']], url=row[schema['url']], thumbnail=row[schema['thumbnail']], provider=provider, source=row[schema['source']], license=row[schema['license']].lower(), license_version=row[schema['license_version']], foreign_landing_url=row[schema['foreign_landing_url']], description=Image.parse_description(meta), extension=Image.get_extension(row[schema['url']]), categories=get_categories(extension, source), aspect_ratio=Image.get_aspect_ratio(height, width), size=Image.get_size(height, width), license_url=Image.get_license_url(meta), mature=Image.get_maturity(meta, row[schema['mature']]), normalized_popularity=Image.get_popularity(meta), authority_boost=Image.get_authority_boost(meta, source), authority_penalty=Image.get_authority_penalty(meta, source) )
def database_row_to_elasticsearch_doc(row, schema): views, comments, likes = None, None, None try: metrics = row[schema['meta_data']]['popularity_metrics'] views = int(metrics['views']) + 1 likes = int(metrics['likes']) + 1 comments = int(metrics['comments']) + 1 except (KeyError, TypeError): pass provider = row[schema['provider']] extension = Image.get_extension(row[schema['url']]) height = row[schema['height']] width = row[schema['width']] return Image( _id=row[schema['id']], id=row[schema['id']], title=row[schema['title']], identifier=row[schema['identifier']], creator=row[schema['creator']], creator_url=row[schema['creator_url']], tags=Image.parse_detailed_tags(row[schema['tags']]), created_on=row[schema['created_on']], url=row[schema['url']], thumbnail=row[schema['thumbnail']], provider=row[schema['provider']], source=row[schema['source']], license=row[schema['license']].lower(), license_version=row[schema['license_version']], foreign_landing_url=row[schema['foreign_landing_url']], view_count=row[schema['view_count']], description=Image.parse_description(row[schema['meta_data']]), height=height, width=width, extension=Image.get_extension(row[schema['url']]), views=views, comments=comments, likes=likes, categories=get_categories(extension, provider), aspect_ratio=Image.get_aspect_ratio(height, width), size=Image.get_size(height, width), license_url=Image.get_license_url(row[schema['meta_data']]), mature=Image.get_maturity(row[schema['meta_data']], row[schema['mature']]))