예제 #1
0
def read_epicurious_data(data: dict, counter: int) -> dict:
    d = {
        'datePublished':
        structured_data.DateTime.fromisoformat(data['pubDate']),
        'name':
        data['hed'],
        'recipeInstructions':
        structured_data.Property(*data['prepSteps']),
        'aggregateRating':
        structured_data.AggregateRating(ratingValue=data['aggregateRating'],
                                        reviewCount=data['reviewsCount'])
    }
    if data['reviewsCount'] != 0:
        d['aggregateRating'] = structured_data.AggregateRating(
            ratingValue=data['aggregateRating'],
            reviewCount=data['reviewsCount'])
    if data['author']:
        d['author'] = structured_data.Property(*[
            structured_data.Person(author['name']) for author in data['author']
        ])
    try:
        d['recipeIngredient'] = structured_data.Property(*data['ingredients'])
    except KeyError as e:
        warnings.warn('KeyError: {} in line#{}'.format(e, counter))
        try:
            if data['tag']['category'] == 'ingredient':
                d['recipeIngredient'] = data['tag']['name']
        except KeyError as e:
            warnings.warn('KeyError: {} in line#{}'.format(e, counter))
    try:
        if data['tag']['category'] == 'cuisine':
            d['recipeCuisine'] = data['tag']['name']
    except KeyError as e:
        warnings.warn('KeyError: {} in line#{}'.format(e, counter))
    return d
예제 #2
0
def read_cookstr_data(data: dict, *args) -> dict:
    d = {
        'cookingMethod': data['cooking_method'],
        'datePublished': data['date_modified'],
        'recipeIngredient': structured_data.Property(*data['ingredients']),
        'recipeInstructions': structured_data.Property(*data['instructions']),
        'name': data['title']
    }
    if data['chef']:
        d['author'] = structured_data.Person(data['chef'])
    if data['description']:
        d['description'] = data['description']
    if data['rating_count']:
        d['aggregateRating'] = structured_data.AggregateRating(
            ratingValue=data['rating_value'], ratingCount=data['rating_count'])
    return d
예제 #3
0
def read_allrecipes_data(data: dict, *args) -> dict:
    d = {
        'author': structured_data.Person(data['author']),
        'description': data['description'],
        'recipeIngredient': structured_data.Property(*data['ingredients']),
        'recipeInstructions': structured_data.Property(*data['instructions']),
        'name': data['title']
    }
    if data['prep_time_minutes'] != 0 or data['cook_time_minutes'] != 0:
        d['prepTime'] = structured_data.Duration(
            minutes=data['prep_time_minutes'])
        d['cookTime'] = structured_data.Duration(
            minutes=data['cook_time_minutes'])
    if data['total_time_minutes'] != 0:
        d['totalTime'] = structured_data.Duration(
            minutes=data['total_time_minutes'])
    if data['review_count']:
        d['aggregateRating'] = structured_data.AggregateRating(
            ratingValue=data['rating_stars'], reviewCount=data['review_count'])
    return d
예제 #4
0
def read_bbccouk_data(data: dict, *args) -> dict:
    d = {
        'author': structured_data.Person(data['chef']),
        'recipeIngredient': structured_data.Property(*data['ingredients']),
        'recipeInstructions': structured_data.Property(*data['instructions']),
        'name': data['title']
    }
    if data['description']:
        d['description'] = data['description']
    if data['preparation_time_minutes'] != 0 or data[
            'cooking_time_minutes'] != 0:
        d['prepTime'] = structured_data.Duration(
            minutes=data['preparation_time_minutes'])
        d['cookTime'] = structured_data.Duration(
            minutes=data['cooking_time_minutes'])
    if data['total_time_minutes'] != 0:
        d['totalTime'] = structured_data.Duration(
            minutes=data['total_time_minutes'])

    # TODO: Also include serving size 'serve' into the data
    return d
예제 #5
0
                    data['hed'],
                    'recipeInstructions':
                    schema.Property(*data['prepSteps']),
                    'aggregateRating':
                    schema.AggregateRating(ratingValue=data['aggregateRating'],
                                           reviewCount=data['reviewsCount'])
                }

                if data['reviewsCount'] != 0:
                    d['aggregateRating'] = schema.AggregateRating(
                        ratingValue=data['aggregateRating'],
                        reviewCount=data['reviewsCount'])

                if data['author']:
                    d['author'] = schema.Property(*[
                        schema.Person(author['name'])
                        for author in data['author']
                    ])

                try:
                    d['recipeIngredient'] = schema.Property(
                        *data['ingredients'])
                except KeyError as e:
                    warnings.warn('KeyError: {} in line#{}'.format(e, counter))
                    try:
                        if data['tag']['category'] == 'ingredient':
                            d['recipeIngredient'] = data['tag']['name']
                    except KeyError as e:
                        warnings.warn('KeyError: {} in line#{}'.format(
                            e, counter))