-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modernproper: removes nutrient titles from output (#1304)
Co-authored-by: James Addison <55152140+jayaddison@users.noreply.github.com>
- Loading branch information
1 parent
097c601
commit bc8cb72
Showing
2 changed files
with
37 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,35 @@ | ||
from ._abstract import AbstractScraper | ||
from ._exceptions import ElementNotFoundInHtml | ||
|
||
|
||
class TheModernProper(AbstractScraper): | ||
@classmethod | ||
def host(cls): | ||
return "themodernproper.com" | ||
|
||
def nutrients(self): | ||
container = self.schema.nutrients() | ||
if not container: | ||
raise ElementNotFoundInHtml("Could not find nutritional info container") | ||
|
||
results = {} | ||
nutrient_mapping = { | ||
"calories": "calories", | ||
"fatContent": "fat", | ||
"saturatedFatContent": "saturated fat", | ||
"carbohydrateContent": "carbohydrates", | ||
"sugarContent": "sugar", | ||
"proteinContent": "protein", | ||
"sodiumContent": "sodium", | ||
"fiberContent": "fiber", | ||
"cholesterolContent": "cholesterol", | ||
} | ||
|
||
for key, value in container.items(): | ||
if key not in nutrient_mapping: | ||
continue | ||
redundant_suffix = nutrient_mapping[key] | ||
if value.endswith(redundant_suffix): | ||
results[key] = value.removesuffix(redundant_suffix).strip() | ||
|
||
return results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters