Skip to content

Commit

Permalink
Added Function to create new Foods
Browse files Browse the repository at this point in the history
  • Loading branch information
Dnic94 committed Aug 21, 2021
1 parent e3bf551 commit 159e5a5
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions myfitnesspal/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,12 +834,16 @@ def set_new_food(self, brand: str, description: str, calories: int, fat: float,
)
if result.status_code == 200:
document = lxml.html.document_fromstring(result.content.decode('utf-8'))
warning = document.xpath("//*[@id='main']/p[1]/span")
print(warning)
# TODO HANDLE DUPLICATE
# TODO HANDLE ALREADY EXISTS
try:
warning = document.xpath("//*[@id='main']/p[1]/span")[0].text
print(warning)
# TODO HANDLE DUPLICATE
# TODO HANDLE ALREADY EXISTS
except:
print("No Warning! :)")
elif result.status_code != 302:
print("Unexpected Behaviour")
return(False)
# TODO ERROR HANDLING

submit3_url = parse.urljoin(self.BASE_URL_SECURE, self.SUBMIT3_PATH)
Expand Down Expand Up @@ -888,11 +892,14 @@ def set_new_food(self, brand: str, description: str, calories: int, fat: float,
)
if result.status_code == 200:
document = lxml.html.document_fromstring(result.content.decode('utf-8'))
error = document.xpath("//*[@id='errorExplanation']/ul/li")
print(error)
try:
error = document.xpath("//*[@id='errorExplanation']/ul/li")[0].text
print(error)
except:
print("No Error :)")

# TODO HANDLE DUPLICATE
# TODO HANDLE ALREADY EXISTS
return (False)
#return (False)

return (True)

0 comments on commit 159e5a5

Please sign in to comment.