on master help sign in
Merge pull request #93 from dalf/master

yahoo, bing_new and dailymotion fixes

commit1e99cf2a0e541a3d2df0104d64fadf955bbccc20 authorAdam Tauber <asciimoo@gmail.com> dateSun 7 Sep 2014, 19:12 (12 years ago) parentc23db1ba4ffedd
3 files changed+29−9
searx/engines/bing_news.py+18−5 searx/engines/dailymotion.py+6−1 searx/engines/yahoo.py+5−3
searx/engines/bing_news.py+18−5
@@ -56,10 +56,14 @@ def response(resp):
5656 link = result.xpath('.//div[@class="newstitle"]/a')[0]
5757 url = link.attrib.get('href')
5858 title = ' '.join(link.xpath('.//text()'))
59− content = escape(' '.join(result.xpath('.//div[@class="sn_txt"]/div//span[@class="sn_snip"]//text()')))
60−
59+ contentXPath = result.xpath('.//div[@class="sn_txt"]/div//span[@class="sn_snip"]//text()')
60+ if contentXPath != None:
61+ content = escape(' '.join(contentXPath))
62+
6163 # parse publishedDate
62− publishedDate = escape(' '.join(result.xpath('.//div[@class="sn_txt"]/div//span[@class="sn_ST"]//span[@class="sn_tm"]//text()')))
64+ publishedDateXPath = result.xpath('.//div[@class="sn_txt"]/div//span[contains(@class,"sn_ST")]//span[contains(@class,"sn_tm")]//text()')
65+ if publishedDateXPath != None:
66+ publishedDate = escape(' '.join(publishedDateXPath))
6367
6468 if re.match("^[0-9]+ minute(s|) ago$", publishedDate):
6569 timeNumbers = re.findall(r'\d+', publishedDate)
@@ -74,9 +78,18 @@ def response(resp):
7478 publishedDate = datetime.now()\
7579 - timedelta(hours=int(timeNumbers[0]))\
7680 - timedelta(minutes=int(timeNumbers[1]))
81+ elif re.match("^[0-9]+ day(s|) ago$", publishedDate):
82+ timeNumbers = re.findall(r'\d+', publishedDate)
83+ publishedDate = datetime.now()\
84+ - timedelta(days=int(timeNumbers[0]))
7785 else:
78− publishedDate = parser.parse(publishedDate)
79−
86+ try:
87+ # FIXME use params['language'] to parse either mm/dd or dd/mm
88+ publishedDate = parser.parse(publishedDate, dayfirst=False)
89+ except TypeError:
90+ # FIXME
91+ publishedDate = datetime.now()
92+
8093 # append result
8194 results.append({'url': url,
8295 'title': title,
searx/engines/dailymotion.py+6−1
@@ -16,8 +16,8 @@ from lxml import html
1616
1717# engine dependent config
1818categories = ['videos']
19−locale = 'en_US'
2019paging = True
20+language_support = True
2121
2222# search-url
2323# see http://www.dailymotion.com/doc/api/obj-video.html
@@ -26,6 +26,11 @@ search_url = 'https://api.dailymotion.com/videos?fields=title,description,durati
2626
2727# do search-request
2828def request(query, params):
29+ if params['language'] == 'all':
30+ locale = 'en-US'
31+ else:
32+ locale = params['language']
33+
2934 params['url'] = search_url.format(
3035 query=urlencode({'search': query, 'localization': locale}),
3136 pageno=params['pageno'])
searx/engines/yahoo.py+5−3
@@ -40,9 +40,11 @@ def parse_url(url_string):
4040 if endpos > -1:
4141 endpositions.append(endpos)
4242
43− end = min(endpositions)
44−
45− return unquote(url_string[start:end])
43+ if start==0 or len(endpositions) == 0:
44+ return url_string
45+ else:
46+ end = min(endpositions)
47+ return unquote(url_string[start:end])
4648
4749
4850# do search-request