added support for optional [date] parameter for MFP plugin#174
added support for optional [date] parameter for MFP plugin#174edillingham wants to merge 3 commits intoedwardslabs:gonzobotfrom
Conversation
|
For this one instead of adding a new requirement could you see if you could use the timeformat.py and timeparse.py in cloudbot/util/? It does a nice job of formating time strings. Check remind.py for examples. |
|
Whoops didn't mean to close this. |
|
It doesn't look like cloudbot.util.time_parse supports anything to do with dates, which is what the plugin requires. I can remove the requirement and add a custom date parser if that's what the project prefers, but should we really reinvent the wheel? |
| request = requests.get(scrape_url.format(text)) | ||
| """ | ||
| <user> [date]- returns macros from the MyFitnessPal food diary of <user> | ||
| optionally, specify [date] to retrieve that day's diary |
There was a problem hiding this comment.
The core will only grab the first line of the docstring for command documentation, you'll want to combine these lines.
| """ | ||
| date = 'today' | ||
|
|
||
| args = text.split() |
There was a problem hiding this comment.
I'd recommend doing text.split(None, 1) to limit the split to only splitting once, since you only want to retrieve 2 parts from text.
| args = text.split() | ||
| user = args[0] | ||
| if(len(args) > 1): | ||
| dt = parser.parse(' '.join(args[1:])) |
There was a problem hiding this comment.
To go along with my comment about the .split(), you wouldn't need to use a join if the text is only split on the first space.
|
|
||
| args = text.split() | ||
| user = args[0] | ||
| if(len(args) > 1): |
There was a problem hiding this comment.
Redundant parentheses in if statement. Format should be if len(args) > 1:
| from cloudbot import hook | ||
|
|
||
| scrape_url = "http://www.myfitnesspal.com/food/diary/{}" | ||
| scrape_url = "http://www.myfitnesspal.com/food/diary/{}?date={}" |
There was a problem hiding this comment.
It would probably be a good idea to use the parameters keyword to requests.get() to pass query parameters rather than formatting them in to the URL. For example:
request = requests.get(scrape_url.format(user), parameters={'date': date})which ensures that the parameter is properly escaped.
| .format(**kwargs)) | ||
|
|
||
| output += " ({})".format(scrape_url.format(text)) | ||
| output += " ({})".format(scrape_url.format(user, date)) |
There was a problem hiding this comment.
This should probably use request.url instead of duplicating the URL generation code.
Sort cmdinfo and potential match help outputs
|
All PRs for gonzobot should be submitted to snoonetIRC/CloudBot now. |
uses python-dateutil to parse date strings instead of requiring a strict format