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

Fixes #472 Add News search support for Mojeek #473

Closed
wants to merge 3 commits into from

Conversation

bhaveshAn
Copy link
Member

@bhaveshAn bhaveshAn commented Jan 25, 2018

Fixes #472
Addresses #468

Checklist

  • I have read the Contribution & Best practices Guide and my PR follows them.
  • My branch is up-to-date with the Upstream master branch.
  • I have added necessary documentation (if appropriate)

Changes proposed in this pull request:

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@bhaveshAn bhaveshAn self-assigned this Jan 25, 2018
@codecov
Copy link

codecov bot commented Jan 25, 2018

Codecov Report

Merging #473 into master will decrease coverage by 0.63%.
The diff coverage is 65.38%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #473      +/-   ##
==========================================
- Coverage   85.26%   84.63%   -0.64%     
==========================================
  Files          28       28              
  Lines         794      820      +26     
==========================================
+ Hits          677      694      +17     
- Misses        117      126       +9
Impacted Files Coverage Δ
test/test_mojeek.py 100% <100%> (ø) ⬆️
app/scrapers/mojeek.py 100% <100%> (ø) ⬆️
app/scrapers/generalized.py 48.64% <11.11%> (-3.32%) ⬇️
app/scrapers/__init__.py 84.37% <50%> (-2.3%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 659dee4...a3fa968. Read the comment docs.

@@ -27,3 +28,23 @@ def parse_response(soup):
print('Mojeek parsed: ' + str(urls))

return urls

@staticmethod
def parse_news_response(soup):
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a suggestion, wouldn't it be a better option to just reuse parse_response, why add redundant code

Copy link
Member Author

Choose a reason for hiding this comment

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

No for more simplified code, we have to stick to making a new function only.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should look into what @dilraj45 said. I don't think it'll make it very complex, here is how I'd go about it

The response parse function while parsing links, attaches a type field to item and returns all results, be it video, news or anything.
Now we just need to filter the ones we need. I think this would be more elegent than creating different function for each type of results we want.
Suggestions ?

Copy link
Member Author

@bhaveshAn bhaveshAn Jan 26, 2018

Choose a reason for hiding this comment

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

So, this is a condition for a feature to add, or your own concern?
The way you both are suggesting is a complex one and through that way we will increase the complexity https://github.com/fossasia/query-server/blob/master/.travis.yml#LC15 and nothing else.

Secondly, its not necessary that only after making the change that you suggested we will be able to add the feature. Though its working properly in the link https://gentle-basin-55487.herokuapp.com/
If this link is not working properly, then Please let me know.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not saying it's not working, it's about writing good code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Please search about the complexity attribute at travis Ci .
We are going to increase flake8 complexity in the manner you are suggesting.
I have tried doing that in Parsijoo Image/Video PR. That's what I am saying.
Additional if else increases complexity in travis

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree @bhaveshAn, that adding if-else will increase the cyclomatic complexity, but I guess we need to decide upon an acceptable term between better coding practices and cyclomatic complexity of the code. Feel free to take your call. Additionally, for this particular engine, the implementation of parse_response and parse_news_response is exactly same, so you can at least, instead of rewriting the whole implementation for parse_news_response, just make a call for parse_response in parse_news_response. This will reduce the boilerplate code, plus testing will be easier. Let me know what are your thoughts about this 😄

Copy link

@rohitsainicool rohitsainicool left a comment

Choose a reason for hiding this comment

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

Amazing 👍

@@ -42,6 +42,8 @@ def feed_gen(query, engine, count=10, qtype=''):
engine = old_names.get(engine, engine)
if engine in ('quora', 'youtube'):
urls = scrapers[engine].search_without_count(query)
elif engine in ('mojeek',) and qtype == 'news':
Copy link
Member

Choose a reason for hiding this comment

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

Why use in ('mojeek',)
You can use if engine == 'mojeek':
Since there is only one option to choose from

Copy link
Member Author

Choose a reason for hiding this comment

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

@gabru-md Made the requested changes 👍
Please review again.

@bhaveshAn bhaveshAn closed this Jan 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add News search support for Mojeek
7 participants