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 #455 Add Image/Video search support for Parsijoo #449

Merged
merged 18 commits into from
Jan 29, 2018

Conversation

bhaveshAn
Copy link
Member

@bhaveshAn bhaveshAn commented Jan 20, 2018

Fixes #455
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:

Providing heroku deployment at https://hidden-forest-11970.herokuapp.com/

@mariobehling @vaibhavsingh97 @ParthS007 Please review. Thanks !!

@codecov
Copy link

codecov bot commented Jan 20, 2018

Codecov Report

Merging #449 into master will decrease coverage by 0.25%.
The diff coverage is 75.55%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #449      +/-   ##
==========================================
- Coverage   85.26%   85.01%   -0.26%     
==========================================
  Files          28       28              
  Lines         794      834      +40     
==========================================
+ Hits          677      709      +32     
- Misses        117      125       +8
Impacted Files Coverage Δ
app/scrapers/generalized.py 48.18% <0%> (-3.78%) ⬇️
test/test_parsijoo.py 100% <100%> (ø) ⬆️
app/scrapers/__init__.py 86.66% <100%> (ø) ⬆️
app/scrapers/parsijoo.py 100% <100%> (ø) ⬆️

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...8d328d9. Read the comment docs.

.travis.yml Outdated
@@ -9,7 +9,7 @@ install:
- pip install -r requirements.txt

before_script:
- flake8 . --count --max-complexity=15 --show-source --statistics
- flake8 . --count --max-complexity=16 --show-source --statistics --max-line-length=100
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to go back to violating PEP8 line length?

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.

Can we refactor to reduce McCabe complexity?

@bhaveshAn bhaveshAn changed the title Addresses #320 and #321 Add Image/Video search support for Parsijoo Fixes #455 Add Image/Video search support for Parsijoo Jan 21, 2018
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.

@bhaveshAn
Copy link
Member Author

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

@realslimshanky
Copy link
Member

For some reason, video URL is not working.
image
image

if urls == []:
return "No video with this Keyword"
else:
return urls
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we just do return urls or "No video with this Keyword" because all other falsey values are just as dangerous as an empty list.

@@ -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 ['parsijoo']) and (qtype == 'isch'):
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 ['parsijoo'] and qtype == 'isch': # Lose the parens... this is not JavaScript.

@@ -42,9 +42,9 @@ 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 ['parsijoo']) and (qtype == 'isch'):
elif engine in ('parsijoo') and qtype == 'isch':
Copy link
Contributor

Choose a reason for hiding this comment

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

('parsijoo') is not a tuple, it is a str. ('parsijoo', ) is a tuple. However the test still works as expected.

$ python3 -c "print(type(('parsijoo')), type(('parsijoo', )))"

[[url1], [url2], ...]
"""
urls = []
for div in soup.findAll('div', attrs={'class': 'image-container overflow'}):
Copy link
Contributor

Choose a reason for hiding this comment

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

for div in soup.find_all('div', class_='image-container overflow'): # for PEP8 compatibility

@bhaveshAn
Copy link
Member Author

@realslimshanky @cclauss I think now you can approve the PR.

@realslimshanky
Copy link
Member

@bhaveshAn please squash your commits.

@bhaveshAn
Copy link
Member Author

Will squash after final approvals of PRs.

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.

flake8 remove --max-line-length=100

"""
urls = []
for div in \
soup.findAll('div', attrs={'class': 'image-container overflow'}):
Copy link
Member Author

Choose a reason for hiding this comment

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

@cclauss

flake8 remove --max-line-length=100

Can't be done to for this reason. Its exceeding the default max-line-length

Copy link
Contributor

@cclauss cclauss Jan 22, 2018

Choose a reason for hiding this comment

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

Please reformat as for div in soup.find_all('div', class_='image-container overflow'): to avoid the backslash and the long line. Both are advised against in PEP8.

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

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_parsijoo.py
Raising and new issue with this thing might help.

@mariobehling
Copy link
Member

Please resolve conflicts.

@bhaveshAn
Copy link
Member Author

Done @mariobehling

@cclauss
Copy link
Contributor

cclauss commented Jan 23, 2018

Two PEP8 violations in this PR can be avoided with a simple one line change.

The modifications to .travis.yml will also become unnecessary.

@bhaveshAn
Copy link
Member Author

@ParthS007 Now, I have also added tests respectively for Image/Video search in test/tests_parsijoo.py
Please review @mariobehling Thanks!!

@bhaveshAn
Copy link
Member Author

@cclauss Added tests at test/tests_parsijoo.py 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 pull request

@cclauss
Copy link
Contributor

cclauss commented Jan 25, 2018

My comments on --max-line-length=100 stand but perhaps others disagree with me.

@bhaveshAn
Copy link
Member Author

@ParthS007 @vaibhavsingh97 @mariobehling Please review

@mariobehling mariobehling merged commit 70a7e96 into fossasia:master Jan 29, 2018
@bhaveshAn bhaveshAn deleted the parsijoo-image branch January 29, 2018 16:05
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 Image/Video search support for Parsijoo
7 participants