-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added support for optional [date] parameter for MFP plugin #174
base: gonzobot
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -45,7 +57,7 @@ def mfp(text, bot): | |||
output += ("{caption}: {total}/{remain}{units} ({pct}%) " | |||
.format(**kwargs)) | |||
|
|||
output += " ({})".format(scrape_url.format(text)) | |||
output += " ({})".format(scrape_url.format(user, date)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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