소스 검색

Merge pull request #93 from dalf/master

yahoo, bing_new and dailymotion fixes
Adam Tauber 10 년 전
부모
커밋
1e99cf2a0e
3개의 변경된 파일29개의 추가작업 그리고 9개의 파일을 삭제
  1. 18
    5
      searx/engines/bing_news.py
  2. 6
    1
      searx/engines/dailymotion.py
  3. 5
    3
      searx/engines/yahoo.py

+ 18
- 5
searx/engines/bing_news.py 파일 보기

56
         link = result.xpath('.//div[@class="newstitle"]/a')[0]
56
         link = result.xpath('.//div[@class="newstitle"]/a')[0]
57
         url = link.attrib.get('href')
57
         url = link.attrib.get('href')
58
         title = ' '.join(link.xpath('.//text()'))
58
         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
+            
61
         # parse publishedDate
63
         # 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))
63
 
67
 
64
         if re.match("^[0-9]+ minute(s|) ago$", publishedDate):
68
         if re.match("^[0-9]+ minute(s|) ago$", publishedDate):
65
             timeNumbers = re.findall(r'\d+', publishedDate)
69
             timeNumbers = re.findall(r'\d+', publishedDate)
74
             publishedDate = datetime.now()\
78
             publishedDate = datetime.now()\
75
                 - timedelta(hours=int(timeNumbers[0]))\
79
                 - timedelta(hours=int(timeNumbers[0]))\
76
                 - timedelta(minutes=int(timeNumbers[1]))
80
                 - 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]))
77
         else:
85
         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
+                
80
         # append result
93
         # append result
81
         results.append({'url': url, 
94
         results.append({'url': url, 
82
                         'title': title, 
95
                         'title': title, 

+ 6
- 1
searx/engines/dailymotion.py 파일 보기

16
 
16
 
17
 # engine dependent config
17
 # engine dependent config
18
 categories = ['videos']
18
 categories = ['videos']
19
-locale = 'en_US'
20
 paging = True
19
 paging = True
20
+language_support = True
21
 
21
 
22
 # search-url
22
 # search-url
23
 # see http://www.dailymotion.com/doc/api/obj-video.html
23
 # see http://www.dailymotion.com/doc/api/obj-video.html
26
 
26
 
27
 # do search-request
27
 # do search-request
28
 def request(query, params):
28
 def request(query, params):
29
+    if params['language'] == 'all':
30
+        locale = 'en-US'
31
+    else:
32
+        locale = params['language']
33
+
29
     params['url'] = search_url.format(
34
     params['url'] = search_url.format(
30
         query=urlencode({'search': query, 'localization': locale}),
35
         query=urlencode({'search': query, 'localization': locale}),
31
         pageno=params['pageno'])
36
         pageno=params['pageno'])

+ 5
- 3
searx/engines/yahoo.py 파일 보기

40
         if endpos > -1:
40
         if endpos > -1:
41
             endpositions.append(endpos)
41
             endpositions.append(endpos)
42
 
42
 
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])
46
 
48
 
47
 
49
 
48
 # do search-request
50
 # do search-request