-
Notifications
You must be signed in to change notification settings - Fork 3
/
signal.py
43 lines (30 loc) · 1.05 KB
/
signal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
from .models import *
from .utils import *
from datetime import datetime
import requests
class SignalNewsIRDataset(BaseDataSource):
URL_REQUEST = 'http://194.117.29.148:8983/solr/signalnews-articles/select'
def __init__(self, processes=4):
BaseDataSource.__init__(self, 'SignalNewsIRDataset')
self.processes = processes
def getResult(self, query, **kwargs):
params = {
'q':'title:(%s) OR content:(%s)' % (query, query),
'rows':2000,
'fl': 'source,title,published'
}
response = requests.get(SignalNewsIRDataset.URL_REQUEST, params=params)
if response.status_code != 200:
return None
response_json = response.json()
results = []
for item in response_json['response']['docs']:
if not (item['title'][0]):
continue
domain_url = item["source"][0]
pubdate = datetime.strptime(item["published"][0], '%Y-%m-%dT%H:%M:%SZ')
title = item['title'][0]
item_result = ResultHeadLine(headline=title, datetime=pubdate, domain=domain_url, url="")
results.append( item_result )
return results