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 #456 Add Image/Video search support for Bing #448

Merged
merged 13 commits into from
Jan 26, 2018

Conversation

bhaveshAn
Copy link
Member

@bhaveshAn bhaveshAn commented Jan 19, 2018

Fixes #456
Addresses #320 and #321

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:

  • Added Image Search support for Bing.
  • Added Video Search support for Bing.

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 !!

Copy link
Member

@realslimshanky realslimshanky left a 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.

@@ -30,3 +34,39 @@ def parse_response(self, soup):
print('Bing parsed: ' + str(urls))

return urls

def parse_video_response(self, soup):
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Contributor

@cclauss cclauss Jan 20, 2018

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))


return urls

def parse_image_response(self, soup):
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Contributor

@Remorax Remorax left a 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
Copy link
Member Author

screenshot from 2018-01-20 15-49-25
screenshot from 2018-01-20 15-49-32
@realslimshanky @Remorax Working fine for me

@realslimshanky
Copy link
Member

@bhaveshAn code quality is equally as important, also debug from the Travis log. Please look into it.

@bhaveshAn
Copy link
Member Author

@realslimshanky

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
Here we are using python-2.7.14

The log is due to
In app/server.py we are using

10           from app.scrapers import feed_gen, scrapers

and since server.py is already in app directory so I have changed it to

10           from scrapers import feed_gen, scrapers

Note: Locally I wasn't able to run the application due to this bug.

code quality is equally as important,
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.

If you are talking about changed to a static method by using @staticmethod and removing self from the position argument. which codacy is reporting, then do see that we have never following that @staticmethod replace self . If you wanna check than check it out at different scrapers https://github.com/fossasia/query-server/tree/master/app/scrapers
This is the reason I have not used @staticmethod in place of self as we while contributing have to see which approach are we following in current codebase of that project.

@bhaveshAn bhaveshAn self-assigned this Jan 20, 2018
@realslimshanky
Copy link
Member

@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.
I would request @vaibhavsingh97, @mariobehling and other contributors to please help us out here.

@bhaveshAn
Copy link
Member Author

@Remorax

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.

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 DETAILS Section of each PR, after merge)
You can check out that Codacy is the thing we are ignoring whenever there is a feature adding PR.
So, I think no need to emphasize on Codacy.

@realslimshanky
Copy link
Member

@bhaveshAn okay. this makes it more clear then. Let's only focus on clearing the Travis build.

@Remorax
Copy link
Contributor

Remorax commented Jan 20, 2018

Um @bhaveshAn I think you tagged me by mistake 😛
Also, in image search can you get the title also like I have done in #447 since we're following the same convention everywhere 😄

@codecov
Copy link

codecov bot commented Jan 20, 2018

Codecov Report

Merging #448 into master will decrease coverage by 1.65%.
The diff coverage is 68.42%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
app/scrapers/bing.py 100% <100%> (ø) ⬆️
test/test_bing.py 100% <100%> (ø) ⬆️
app/server.py 84.88% <100%> (+0.17%) ⬆️
app/scrapers/generalized.py 66.66% <11.11%> (-19.61%) ⬇️
app/scrapers/__init__.py 89.28% <50%> (-6.55%) ⬇️

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 423896a...26d8459. Read the comment docs.

@bhaveshAn
Copy link
Member Author

@realslimshanky Now you can check Travis as well.

@vaibhavsingh97 @gabru-md @cclauss Please review

@cclauss
Copy link
Contributor

cclauss commented Jan 20, 2018

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.

Copy link
Contributor

@cclauss cclauss left a 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.

@bhaveshAn bhaveshAn changed the title Addresses #320 and #321 Add Image/Video search support for Bing Fixes #456 Add Image/Video search support for Bing Jan 21, 2018
@bhaveshAn
Copy link
Member Author

@realslimshanky @cclauss @vaibhavsingh97 Please review.
Codacy and Travis CI both are passing their tests.

Copy link
Member

@realslimshanky realslimshanky left a 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.

@@ -0,0 +1,51 @@
{
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done 👍

@@ -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'):
Copy link
Member

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').

Copy link
Contributor

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

Copy link
Member

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:
Copy link
Contributor

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.

@@ -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'):
Copy link
Contributor

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

@bhaveshAn
Copy link
Member Author

@realslimshanky @cclauss Now you can approve PR.
Will squash commits after approval.

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:
Copy link
Contributor

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'?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done 👍

@bhaveshAn
Copy link
Member Author

@mariobehling Please review and merge. Thanks!!

Copy link
Member

@ParthS007 ParthS007 left a 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?

@bhaveshAn
Copy link
Member Author

@ParthS007
Its because for every feature based PR, there is no test in test directory. Not relevant to this PR.
Check here https://github.com/fossasia/query-server/blob/master/test/test_bing.py
Raising new issue with this thing might help.

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.

Awesome 👍

@mariobehling
Copy link
Member

Please resolve conflicts.

@bhaveshAn
Copy link
Member Author

Done @mariobehling

@bhaveshAn
Copy link
Member Author

@ParthS007 Now I have added the tests in test/test_bing.py and in overall its not decreasing the coverage.
@mariobehling Please review. Thanks !!

Copy link
Member

@ParthS007 ParthS007 left a 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 👍

@bhaveshAn
Copy link
Member Author

@ParthS007 Please approve the PR.

@mariobehling mariobehling merged commit bd30392 into fossasia:master Jan 26, 2018
@bhaveshAn bhaveshAn deleted the bing branch January 26, 2018 14:11
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.

Add Image/Video search support for Bing
7 participants