Skip to content
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

Refactored the project #19

Merged
merged 1 commit into from
Dec 8, 2016
Merged

Conversation

ayuhsya
Copy link
Contributor

@ayuhsya ayuhsya commented Dec 6, 2016

Created two new python scripts:

core.py Contains the main WikiPage class with methods for each Wiki property.
helpers.py Contain methods to strip the JSON response.

And deleted the scripts wiki_cat.py, wiki_linkshere.py, wiki_images.py whose methods have been added in core.py script.

@abinashmeher999
Copy link
Owner

@ayuhsya The PR looks great! 💯 Wonderfully arranged. I will review the PR properly tomorrow. Meanwhile @djr-jsr can you review the PR?

}

# Method to fetch categories
def get_categories(self, clshow="!hidden"):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the motivations of this project is so that the users need not bother themselves with the details of the API. Try to use generic names wherever possible. clshow is very misleading who isn't familiar with the API.

@@ -0,0 +1,19 @@
import re
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need not create a separate file for helpers. Better keep them in the same file as core.py outside WikiPage class and prefix them with _. Names starting with _ are supposed to refer to functions that should not be messed with by the user unless the user is sure what they are doing. "We're all consenting adults here" 😉


img_list = helpers.beautiful(res, prop, 'File')
while 'continue' in res:
payload['imcontinue'] = res['continue']['imcontinue']
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be self.payload.

return res['query']['pages'][pageids][prop]


def beautiful(res, prop, strip_chars):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a better name for this 🤔

for pageid, page_content in res['query']['pages'].items():
if prop not in page_content:
continue
ret[pageid] = [strip_prop(content['title'], strip_chars) for content in page_content[prop]]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entry seems like a better replacement for content here.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ayuhsya I meant [strip_prop(entry['title'], strip_chars) for entry in page_content[prop]]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! 😐

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abinashmeher999 I've changed the variable name.

@ayuhsya
Copy link
Contributor Author

ayuhsya commented Dec 8, 2016

@abinashmeher999 I've made the changes. I've deleted helpers.py but imo it will be required later when you'll see that core.py script is too long with all the methods for each API property. We'll be scrolling all the time to find where the helper methods are defined.

wk = WikiPage('843158','20715044')
pprint(wk.get_categories())
#pprint(wk.get_images())
#pprint(wk.get_linkshere())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you uncomment these 2? I need to check the output once just to be sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abinashmeher999 Okay, done.

@ayuhsya
Copy link
Contributor Author

ayuhsya commented Dec 8, 2016

@abinashmeher999 Every time I'm asked to make a change, I follow these commands to push them:

git add .
git commit -m "some message"
git rebase -i HEAD~2
git push origin +<name of branch>

I did rebase because you once asked me to squash all commits in one before making a PR.
Is this the right way or is there a better way?

@abinashmeher999
Copy link
Owner

Squashing them is your choice. I asked them the last time because some of the commits had unclear names and some changes didn't need to have a commit of there own. In this case you could have kept separate commits. There's nothing like squashing all the commits in a PR is a good practice. I would advise that you fetch the upstream and rebase on top of the branch you are working on.

@abinashmeher999 abinashmeher999 merged commit 351f512 into abinashmeher999:master Dec 8, 2016
@abinashmeher999
Copy link
Owner

Addresses #7

@ayuhsya
Copy link
Contributor Author

ayuhsya commented Dec 8, 2016

And #15 too.
And maybe #3 too.

@abinashmeher999
Copy link
Owner

@ayuhsya It doesn't address #3 fully. Maybe you can try that next. Very easy. Won't even take an hour.

@abinashmeher999
Copy link
Owner

And of course the module name is not sample.

@ayuhsya ayuhsya deleted the slave branch December 8, 2016 10:51
@ayuhsya
Copy link
Contributor Author

ayuhsya commented Dec 8, 2016

@abinashmeher999 It says in the guide that the main module should reside in the sample folder.

@abinashmeher999
Copy link
Owner

@ayuhsya 😐 That's because the project name is 'sample' https://github.com/kennethreitz/samplemod/blob/master/setup.py

@ayuhsya
Copy link
Contributor Author

ayuhsya commented Dec 8, 2016

😢 Damn, I thought that was the standard.

@abinashmeher999
Copy link
Owner

😆 We all have been there.

@ayuhsya ayuhsya restored the slave branch December 9, 2016 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants