Update aggregator.py
Browse files- aggregator.py +1 -52
aggregator.py
CHANGED
@@ -45,28 +45,6 @@ def get_articles_sentiment(ticker, model):
|
|
45 |
print(e)
|
46 |
vantage_results = []
|
47 |
|
48 |
-
try:
|
49 |
-
marketaux_list = get_marketaux(ticker)
|
50 |
-
marketaux_results = pipe(marketaux_list)
|
51 |
-
except Exception as e:
|
52 |
-
print(e)
|
53 |
-
marketaux_results = []
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
# finhub_list = get_finhub(ticker)
|
58 |
-
# marketaux_list = get_marketaux(ticker)
|
59 |
-
# newsapi_list = get_newsapi(ticker)
|
60 |
-
# newsdata_list = get_newsdata(ticker)
|
61 |
-
# vantage_list = get_vantage(ticker)
|
62 |
-
|
63 |
-
|
64 |
-
# calling ai model on each list
|
65 |
-
# finhub_results = pipe(finhub_list)
|
66 |
-
# marketaux_results = pipe(marketaux_list)
|
67 |
-
# newsapi_results = pipe(newsapi_list)
|
68 |
-
# newsdata_results = pipe(newsdata_list)
|
69 |
-
# vantage_results = pipe(vantage_list)
|
70 |
|
71 |
# replacing values for calculations and doing the sentiment for each source
|
72 |
def replace_values(result):
|
@@ -78,7 +56,7 @@ def get_articles_sentiment(ticker, model):
|
|
78 |
dict["label"] = 1
|
79 |
|
80 |
|
81 |
-
total_articles = len(bezinga_results) + len(finhub_results) + len(
|
82 |
|
83 |
bezinga_positives = []
|
84 |
bezinga_negatives = []
|
@@ -86,9 +64,6 @@ def get_articles_sentiment(ticker, model):
|
|
86 |
finhub_positives = []
|
87 |
finhub_negatives = []
|
88 |
|
89 |
-
marketaux_positives = []
|
90 |
-
marketaux_negatives = []
|
91 |
-
|
92 |
newsapi_positives = []
|
93 |
newsapi_negatives = []
|
94 |
|
@@ -138,24 +113,6 @@ def get_articles_sentiment(ticker, model):
|
|
138 |
|
139 |
if len(finhub_negatives) > 0:
|
140 |
finhub_negative_score_mean = float(sum(d['score'] for d in finhub_negatives)) / len(finhub_negatives)
|
141 |
-
|
142 |
-
# marketaux
|
143 |
-
if len(marketaux_results) > 0:
|
144 |
-
replace_values(marketaux_results)
|
145 |
-
|
146 |
-
marketaux_label_mean = float(sum(d['label'] for d in marketaux_results)) / len(marketaux_results)
|
147 |
-
|
148 |
-
for dict in marketaux_results:
|
149 |
-
if dict["label"] == 2:
|
150 |
-
marketaux_positives.append(dict)
|
151 |
-
else:
|
152 |
-
marketaux_negatives.append(dict)
|
153 |
-
|
154 |
-
if len(marketaux_positives) > 0:
|
155 |
-
marketaux_positive_score_mean = float(sum(d['score'] for d in marketaux_positives)) / len(marketaux_positives)
|
156 |
-
|
157 |
-
if len(marketaux_negatives) > 0:
|
158 |
-
marketaux_negative_score_mean = float(sum(d['score'] for d in marketaux_negatives)) / len(marketaux_negatives)
|
159 |
|
160 |
# newsapi
|
161 |
if len(newsapi_results) > 0:
|
@@ -232,14 +189,6 @@ def get_articles_sentiment(ticker, model):
|
|
232 |
"finhub_positive_score_mean": finhub_positive_score_mean if len(finhub_results) > 0 else 0,
|
233 |
"finhub_negative_score_mean": finhub_negative_score_mean if len(finhub_results) > 0 else 0
|
234 |
},
|
235 |
-
"marketaux": {
|
236 |
-
"marketaux_articles": len(marketaux_results),
|
237 |
-
"marketaux_positives": len(marketaux_positives),
|
238 |
-
"marketaux_negatives": len(marketaux_negatives),
|
239 |
-
"marketaux_sentiment_mean": marketaux_label_mean if len(marketaux_results) > 0 else 0,
|
240 |
-
"marketaux_positive_score_mean": marketaux_positive_score_mean if len(marketaux_results) > 0 else 0,
|
241 |
-
"marketaux_negative_score_mean": marketaux_negative_score_mean if len(marketaux_results) > 0 else 0
|
242 |
-
},
|
243 |
"newsapi": {
|
244 |
"newsapi_articles": len(newsapi_results),
|
245 |
"newsapi_positives": len(newsapi_positives),
|
|
|
45 |
print(e)
|
46 |
vantage_results = []
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
# replacing values for calculations and doing the sentiment for each source
|
50 |
def replace_values(result):
|
|
|
56 |
dict["label"] = 1
|
57 |
|
58 |
|
59 |
+
total_articles = len(bezinga_results) + len(finhub_results) + len(newsapi_results) + len(newsdata_results) + len(vantage_results)
|
60 |
|
61 |
bezinga_positives = []
|
62 |
bezinga_negatives = []
|
|
|
64 |
finhub_positives = []
|
65 |
finhub_negatives = []
|
66 |
|
|
|
|
|
|
|
67 |
newsapi_positives = []
|
68 |
newsapi_negatives = []
|
69 |
|
|
|
113 |
|
114 |
if len(finhub_negatives) > 0:
|
115 |
finhub_negative_score_mean = float(sum(d['score'] for d in finhub_negatives)) / len(finhub_negatives)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
|
117 |
# newsapi
|
118 |
if len(newsapi_results) > 0:
|
|
|
189 |
"finhub_positive_score_mean": finhub_positive_score_mean if len(finhub_results) > 0 else 0,
|
190 |
"finhub_negative_score_mean": finhub_negative_score_mean if len(finhub_results) > 0 else 0
|
191 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
"newsapi": {
|
193 |
"newsapi_articles": len(newsapi_results),
|
194 |
"newsapi_positives": len(newsapi_positives),
|