-
Notifications
You must be signed in to change notification settings - Fork 264
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 #456 Add Image/Video search support for Bing #448
Conversation
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.
Please go through the review and also try to re-run Travis build.
app/scrapers/bing.py
Outdated
@@ -30,3 +34,39 @@ def parse_response(self, soup): | |||
print('Bing parsed: ' + str(urls)) | |||
|
|||
return urls | |||
|
|||
def parse_video_response(self, soup): |
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 method can be changed to a static method by using @staticmethod
and removing self
from the position argument.
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.
Since previously it was not useful so not using this time too.
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.
That is a really poor answer. The suggested modification is indeed useful as the linter is trying to help you to avoid unnecessary runtime overhead.
https://www.codacy.com/app/fossasia/query-server/pullRequest?prid=1252888#newIssuesView
Normal: 0.5956953540444374
Class: 0.38477163994684815
Static: 0.18970419897232205 # Three times faster than the normal method call.
#!/usr/bin/env python3
from timeit import timeit
setup = """
class TestClass:
def add_normal_method(self, i):
return i + 1
@classmethod
def add_class_method(cls, i):
return i + 1
@staticmethod
def add_static_method(i):
return i + 1
t = TestClass()"""
print('Normal:', timeit('t.add_normal_method(1)', setup))
print(' Class:', timeit('t.add_class_method(1)', setup))
print('Static:', timeit('t.add_static_method(1)', setup))
app/scrapers/bing.py
Outdated
|
||
return urls | ||
|
||
def parse_image_response(self, soup): |
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 method can be changed to a static method by using @staticmethod
and removing self
from the position argument. Codacy also suggests the same modification.
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.
Since previously it was not useful so not using this time too.
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 link doesn't seem to work for me. Can you check it once again?
|
@bhaveshAn code quality is equally as important, also debug from the Travis log. Please look into it. |
Travis is failing in Python3 which has nothing to do with production python version. See at https://github.com/fossasia/query-server/blob/master/runtime.txt The log is due to
and since
Note: Locally I wasn't able to run the application due to this bug.
If you are talking about |
@bhaveshAn there might be 2 scenarios because of which this might be happening. Either Codacy was added recently for the code quality review or else this feature has been added recently to Codacy. Either way, it's not required for the PR to be merged. We can follow our own convention of defining methods. |
Nope, If you have gone through the PRs you will get that Codacy is the thing which is in this project from too long and specially #319 #318 #287 #240 #230 Here Codacy has failed and still we had added the feature (SEE under |
@bhaveshAn okay. this makes it more clear then. Let's only focus on clearing the Travis build. |
Um @bhaveshAn I think you tagged me by mistake 😛 |
Codecov Report
@@ Coverage Diff @@
## master #448 +/- ##
=========================================
- Coverage 89.15% 87.5% -1.66%
=========================================
Files 28 28
Lines 664 720 +56
=========================================
+ Hits 592 630 +38
- Misses 72 90 +18
Continue to review full report at Codecov.
|
@realslimshanky Now you can check Travis as well. @vaibhavsingh97 @gabru-md @cclauss Please review |
Why this persist in clinging to legacy Python? Also the argument that is a good idea to make our code slow for "code consistency" reasons is quite weak. |
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.
Ignores good performance suggestions.
@realslimshanky @cclauss @vaibhavsingh97 Please review. |
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.
Please squash your commits.
package-lock.json
Outdated
@@ -0,0 +1,51 @@ | |||
{ |
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.
Please remove this generated file from the PR, adding it to .gitignore
would be a good option.
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.
Check out https://medium.com/@Quigley_Ja/everything-you-wanted-to-know-about-package-lock-json-b81911aa8ab8#1c9a
Require to commit package-lock.json
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.
Since this file hasn't been added to the repository yet, it should be segregated from the current issue which is trying to add Image/Video support. Let's create a separate issue for the package-lock.json
.
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.
Done 👍
app/scrapers/__init__.py
Outdated
@@ -42,6 +42,10 @@ 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 ['bing']) and (qtype == 'vid'): |
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 be helpful if we follow the same convention for conditional statements. As line 43 uses a tuple, we should use tuple for line 45 and 47 as well, i.e. changing engine in ['bing']
to engine in ('bing')
.
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.
elif engine in ['bing'] and qtype == 'vid':
# Lose the extra parens -- this is not JavaScript
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 was talking about the use of list and tuple in the conditional statements. We should follow one convention to reduce confusion and better readability.
app/server.py
Outdated
from scrapers import feed_gen, scrapers | ||
except Exception as e: |
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 seems to be going in the wrong direction. From PEP8: "When catching exceptions, mention specific exceptions whenever possible". Also, why create an unused variable (e)? Linters will properly complain.
app/scrapers/__init__.py
Outdated
@@ -42,6 +42,10 @@ 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 ['bing']) and (qtype == 'vid'): |
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.
elif engine in ['bing'] and qtype == 'vid':
# Lose the extra parens -- this is not JavaScript
@realslimshanky @cclauss Now you can approve PR. |
app/server.py
Outdated
@@ -80,7 +80,8 @@ def search(search_engine): | |||
unicode # unicode is undefined in Python 3 so NameError is raised | |||
for line in result: | |||
line['link'] = line['link'].encode('utf-8') | |||
line['title'] = line['title'].encode('utf-8') | |||
if 'desc' in line: |
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.
Should be 'title', not 'desc'?
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.
Done 👍
@mariobehling Please review and merge. Thanks!! |
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.
@bhaveshAn Please check why your PR is decreasing Code coverage?
@ParthS007 |
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.
Awesome 👍
Please resolve conflicts. |
Done @mariobehling |
@ParthS007 Now I have added the tests in |
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.
LGTM ! Please squash the commits 👍
@ParthS007 Please approve the PR. |
Fixes #456
Addresses #320 and #321
Checklist
master
branch.Changes proposed in this pull request:
Note Since bing image search and video search respectively at https://www.bing.com/images/search?q=fossasia&FORM=HDRSC2 and https://www.bing.com/videos/search?q=fossasia&FORM=HDRSC3 doesn't support page indexing. Hence, results will come without count, such as we had for Quora and Youtube.
Providing the heroku deployment at https://pacific-wildwood-54349.herokuapp.com/
@mariobehling @vaibhavsingh97 @dgarvit @realslimshanky Please review. Thanks !!