-
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
Changes from 2 commits
946781a
4cda2e0
42a36ce
e54dbbb
978015d
5c009be
15ba9b3
da47877
e16ebfe
81c3de7
da58033
8c9f058
26d8459
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,9 +8,13 @@ class Bing(Scraper): | |
def __init__(self): | ||
Scraper.__init__(self) | ||
self.url = 'http://www.bing.com/search' | ||
self.videoURL = 'https://www.bing.com/videos/search' | ||
self.imageURL = 'https://www.bing.com/images/search' | ||
self.defaultStart = 1 | ||
self.startKey = 'first' | ||
self.name = 'bing' | ||
self.videoKey = 'FORM' | ||
self.imageKey = 'FORM' | ||
|
||
def parse_response(self, soup): | ||
""" Parses the reponse and return set of urls | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. This method can be changed to a static method by using There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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
#!/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)) |
||
""" Parse response and returns the urls | ||
|
||
Returns: urls (list) | ||
[[Tile1, url1], [Title2, url2], ...] | ||
""" | ||
urls = [] | ||
for a in soup.findAll('a', attrs={'class': 'mc_vtvc_link'}): | ||
title = a.get('aria-label').split(' Duration')[0] | ||
url = 'https://www.bing.com' + a.get('href') | ||
urls.append({ | ||
'title': title, | ||
'link': url | ||
}) | ||
|
||
print('Bing parsed: ' + str(urls)) | ||
|
||
return urls | ||
|
||
def parse_image_response(self, soup): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method can be changed to a static method by using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since previously it was not useful so not using this time too. |
||
""" Parse response and returns the urls | ||
|
||
Returns: urls (list) | ||
[[url1], [url2], ...] | ||
""" | ||
urls = [] | ||
for a in soup.findAll('a', attrs={'class': 'iusc'}): | ||
url = 'https://www.bing.com' + a.get('href') | ||
urls.append({ | ||
'link': url | ||
}) | ||
|
||
print('Bing parsed: ' + str(urls)) | ||
|
||
return urls |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Done 👍 |
||
line['title'] = line['title'].encode('utf-8') | ||
if 'desc' in line: | ||
line['desc'] = line['desc'].encode('utf-8') | ||
except NameError: | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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']
toengine 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 JavaScriptThere 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.