add core.ac.uk engine
This commit is contained in:
		
							parent
							
								
									4863c1933e
								
							
						
					
					
						commit
						7528e38c8a
					
				
							
								
								
									
										63
									
								
								searx/engines/core.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								searx/engines/core.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,63 @@
 | 
				
			|||||||
 | 
					# SPDX-License-Identifier: AGPL-3.0-or-later
 | 
				
			||||||
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Core Engine (science)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from json import loads
 | 
				
			||||||
 | 
					from datetime import datetime
 | 
				
			||||||
 | 
					from urllib.parse import urlencode
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					about = {
 | 
				
			||||||
 | 
					    "website": 'https://core.ac.uk',
 | 
				
			||||||
 | 
					    "wikidata_id": 'Q22661180',
 | 
				
			||||||
 | 
					    "official_api_documentation": 'https://core.ac.uk/documentation/api/',
 | 
				
			||||||
 | 
					    "use_official_api": True,
 | 
				
			||||||
 | 
					    "require_api_key": True,
 | 
				
			||||||
 | 
					    "results": 'JSON',
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					categories = ['science']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					paging = True
 | 
				
			||||||
 | 
					nb_per_page = 20
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# apikey = ''
 | 
				
			||||||
 | 
					apikey = 'MVBozuTX8QF9I1D0GviL5bCn2Ueat6NS'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					base_url = 'https://core.ac.uk:443/api-v2/search/'
 | 
				
			||||||
 | 
					search_string = '{query}?page={page}&pageSize={nb_per_page}&apiKey={apikey}'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def request(query, params):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    search_path = search_string.format(
 | 
				
			||||||
 | 
					        query=urlencode({'q': query}),
 | 
				
			||||||
 | 
					        nb_per_page=nb_per_page,
 | 
				
			||||||
 | 
					        page=params['pageno'],
 | 
				
			||||||
 | 
					        apikey=apikey)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    params['url'] = base_url + search_path
 | 
				
			||||||
 | 
					    return params
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def response(resp):
 | 
				
			||||||
 | 
					    results = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    json_data = loads(resp.text)
 | 
				
			||||||
 | 
					    for result in json_data['data']:
 | 
				
			||||||
 | 
					        time = result['_source']['publishedDate']
 | 
				
			||||||
 | 
					        if time is None:
 | 
				
			||||||
 | 
					            date = datetime.now()
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            date = datetime.fromtimestamp(time / 1000)
 | 
				
			||||||
 | 
					        results.append({
 | 
				
			||||||
 | 
					            'url': result['_source']['urls'][0],
 | 
				
			||||||
 | 
					            'title': result['_source']['title'],
 | 
				
			||||||
 | 
					            'content': result['_source']['description'],
 | 
				
			||||||
 | 
					            'publishedDate': date})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return results
 | 
				
			||||||
@ -272,6 +272,15 @@ engines:
 | 
				
			|||||||
    categories : images
 | 
					    categories : images
 | 
				
			||||||
    shortcut : cce
 | 
					    shortcut : cce
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  - name : core.ac.uk
 | 
				
			||||||
 | 
					    engine : core
 | 
				
			||||||
 | 
					    categories : science
 | 
				
			||||||
 | 
					    shortcut : cor
 | 
				
			||||||
 | 
					    # get your API key from: https://core.ac.uk/api-keys/register/
 | 
				
			||||||
 | 
					    # api_key : "xxxxxxxx"
 | 
				
			||||||
 | 
					    # set api_key and comment out disabled ..
 | 
				
			||||||
 | 
					    disabled: True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  - name : crossref
 | 
					  - name : crossref
 | 
				
			||||||
    engine : json_engine
 | 
					    engine : json_engine
 | 
				
			||||||
    paging : True
 | 
					    paging : True
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user