Andreagus commited on
Commit
4ec76d2
1 Parent(s): 259c7f2

Update aggregator.py

Browse files
Files changed (1) hide show
  1. aggregator.py +68 -63
aggregator.py CHANGED
@@ -16,41 +16,41 @@ def get_articles_sentiment(ticker, model):
16
  bezinga_results = pipe(bezinga_list)
17
  except Exception as e:
18
  print(e)
19
- bezinga_results = 0
20
 
21
  try:
22
  newsapi_list = get_newsapi(ticker)
23
  newsapi_results = pipe(newsapi_list)
24
  except Exception as e:
25
  print(e)
26
- newsapi_results = 0
27
  try:
28
  newsdata_list = get_newsdata(ticker)
29
  newsdata_results = pipe(newsdata_list)
30
  except Exception as e:
31
  print(e)
32
- newsdata_results = 0
33
 
34
  try:
35
  finhub_list = get_finhub(ticker)
36
  finhub_results = pipe(finhub_list)
37
  except Exception as e:
38
  print(e)
39
- finhub_results = 0
40
 
41
  try:
42
  vantage_list = get_vantage(ticker)
43
  vantage_results = pipe(vantage_list)
44
  except Exception as e:
45
  print(e)
46
- vantage_results = 0
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 = 0
54
 
55
 
56
 
@@ -76,16 +76,34 @@ def get_articles_sentiment(ticker, model):
76
  dict["label"] = 2
77
  else:
78
  dict["label"] = 1
 
79
 
80
  total_articles = len(bezinga_results) + len(finhub_results) + len(marketaux_results) + len(newsapi_results) + len(newsdata_results) + len(vantage_results)
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  try:
83
  replace_values(bezinga_results)
84
 
85
  bezinga_label_mean = float(sum(d['label'] for d in bezinga_results)) / len(bezinga_results)
86
 
87
- bezinga_positives = []
88
- bezinga_negatives = []
89
 
90
  for dict in bezinga_results:
91
  if dict["label"] == 2:
@@ -102,13 +120,12 @@ def get_articles_sentiment(ticker, model):
102
  print(e)
103
 
104
  # finhub
105
- if finhub_results:
106
  replace_values(finhub_results)
107
 
108
  finhub_label_mean = float(sum(d['label'] for d in finhub_results)) / len(finhub_results)
109
 
110
- finhub_positives = []
111
- finhub_negatives = []
112
 
113
  for dict in finhub_results:
114
  if dict["label"] == 2:
@@ -123,13 +140,10 @@ def get_articles_sentiment(ticker, model):
123
  finhub_negative_score_mean = float(sum(d['score'] for d in finhub_negatives)) / len(finhub_negatives)
124
 
125
  # marketaux
126
- if marketaux_results:
127
  replace_values(marketaux_results)
128
 
129
  marketaux_label_mean = float(sum(d['label'] for d in marketaux_results)) / len(marketaux_results)
130
-
131
- marketaux_positives = []
132
- marketaux_negatives = []
133
 
134
  for dict in marketaux_results:
135
  if dict["label"] == 2:
@@ -144,13 +158,10 @@ def get_articles_sentiment(ticker, model):
144
  marketaux_negative_score_mean = float(sum(d['score'] for d in marketaux_negatives)) / len(marketaux_negatives)
145
 
146
  # newsapi
147
- if newsapi_results:
148
  replace_values(newsapi_results)
149
 
150
  newsapi_label_mean = float(sum(d['label'] for d in newsapi_results) + 1) / (len(newsapi_results) + 2)
151
-
152
- newsapi_positives = []
153
- newsapi_negatives = []
154
 
155
  for dict in newsapi_results:
156
  if dict["label"] == 2:
@@ -166,13 +177,10 @@ def get_articles_sentiment(ticker, model):
166
 
167
 
168
  # newsdata
169
- if newsdata_results:
170
  replace_values(newsdata_results)
171
 
172
  newsdata_label_mean = float(sum(d['label'] for d in newsdata_results)) / len(newsdata_results)
173
-
174
- newsdata_positives = []
175
- newsdata_negatives = []
176
 
177
  for dict in newsdata_results:
178
  if dict["label"] == 2:
@@ -187,13 +195,10 @@ def get_articles_sentiment(ticker, model):
187
  newsdata_negative_score_mean = float(sum(d['score'] for d in newsdata_negatives)) / len(newsdata_negatives)
188
 
189
  # vantage
190
- if vantage_results:
191
  replace_values(vantage_results)
192
 
193
  vantage_label_mean = float(sum(d['label'] for d in vantage_results)) / len(vantage_results)
194
-
195
- vantage_positives = []
196
- vantage_negatives = []
197
 
198
  for dict in vantage_results:
199
  if dict["label"] == 2:
@@ -212,52 +217,52 @@ def get_articles_sentiment(ticker, model):
212
 
213
  results_dict = {
214
  "bezinga": {
215
- "bezinga_articles": len(bezinga_results) if bezinga_results > 0 else 0,
216
- "bezinga_positives": len(bezinga_positives) if bezinga_results > 0 else 0,
217
- "bezinga_negatives": len(bezinga_negatives) if bezinga_results > 0 else 0,
218
- "bezinga_sentiment_mean": bezinga_label_mean if bezinga_results > 0 else 0,
219
- "bezinga_positive_score_mean": bezinga_positive_score_mean if bezinga_results > 0 else 0,
220
- "bezinga_negative_score_mean": bezinga_negative_score_mean if bezinga_results > 0 else 0
221
  },
222
  "finhub": {
223
- "finhub_articles": len(finhub_results) if finhub_results > 0 else 0,
224
- "finhub_positives": len(finhub_positives) if finhub_results > 0 else 0,
225
- "finhub_negatives": len(finhub_negatives) if finhub_results > 0 else 0,
226
- "finhub_sentiment_mean": finhub_label_mean if finhub_results > 0 else 0,
227
- "finhub_positive_score_mean": finhub_positive_score_mean if finhub_results > 0 else 0,
228
- "finhub_negative_score_mean": finhub_negative_score_mean if finhub_results > 0 else 0
229
  },
230
  "marketaux": {
231
- "marketaux_articles": len(marketaux_results) if marketaux_results > 0 else 0,
232
- "marketaux_positives": len(marketaux_positives) if marketaux_results > 0 else 0,
233
- "marketaux_negatives": len(marketaux_negatives) if marketaux_results > 0 else 0,
234
- "marketaux_sentiment_mean": marketaux_label_mean if marketaux_results > 0 else 0,
235
- "marketaux_positive_score_mean": marketaux_positive_score_mean if marketaux_results > 0 else 0,
236
- "marketaux_negative_score_mean": marketaux_negative_score_mean if marketaux_results > 0 else 0
237
  },
238
  "newsapi": {
239
- "newsapi_articles": len(newsapi_results) if newsapi_results > 0 else 0,
240
- "newsapi_positives": len(newsapi_positives) if newsapi_results > 0 else 0,
241
- "newsapi_negatives": len(newsapi_negatives) if newsapi_results > 0 else 0,
242
- "newsapi_sentiment_mean": newsapi_label_mean if newsapi_results > 0 else 0,
243
- "newsapi_positive_score_mean": newsapi_positive_score_mean if newsapi_results > 0 else 0,
244
- "newsapi_negative_score_mean": newsapi_negative_score_mean if newsapi_results > 0 else 0
245
  },
246
  "newsdata": {
247
- "newsdata_articles": len(newsdata_results) if newsdata_results > 0 else 0,
248
- "newsdata_positives": len(newsdata_positives) if newsdata_results > 0 else 0,
249
- "newsdata_negatives": len(newsdata_negatives) if newsdata_results > 0 else 0,
250
- "newsdata_sentiment_mean": newsdata_label_mean if newsdata_results > 0 else 0,
251
- "newsdata_positive_score_mean": newsdata_positive_score_mean if newsdata_results > 0 else 0,
252
- "newsdata_negative_score_mean": newsdata_negative_score_mean if newsdata_results > 0 else 0
253
  },
254
  "vantage": {
255
- "vantage_articles": len(vantage_results) if vantage_results > 0 else 0,
256
- "vantage_positives": len(vantage_positives) if vantage_results > 0 else 0,
257
- "vantage_negatives": len(vantage_negatives) if vantage_results > 0 else 0,
258
- "vantage_sentiment_mean": vantage_label_mean if vantage_results > 0 else 0,
259
- "vantage_positive_score_mean": vantage_positive_score_mean if vantage_results > 0 else 0,
260
- "vantage_negative_score_mean": vantage_negative_score_mean if vantage_results > 0 else 0
261
  },
262
  "total_articles": total_articles,
263
  "total_positives": total_positives,
 
16
  bezinga_results = pipe(bezinga_list)
17
  except Exception as e:
18
  print(e)
19
+ bezinga_results = []
20
 
21
  try:
22
  newsapi_list = get_newsapi(ticker)
23
  newsapi_results = pipe(newsapi_list)
24
  except Exception as e:
25
  print(e)
26
+ newsapi_results = []
27
  try:
28
  newsdata_list = get_newsdata(ticker)
29
  newsdata_results = pipe(newsdata_list)
30
  except Exception as e:
31
  print(e)
32
+ newsdata_results = []
33
 
34
  try:
35
  finhub_list = get_finhub(ticker)
36
  finhub_results = pipe(finhub_list)
37
  except Exception as e:
38
  print(e)
39
+ finhub_results = []
40
 
41
  try:
42
  vantage_list = get_vantage(ticker)
43
  vantage_results = pipe(vantage_list)
44
  except Exception as e:
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
 
 
76
  dict["label"] = 2
77
  else:
78
  dict["label"] = 1
79
+
80
 
81
  total_articles = len(bezinga_results) + len(finhub_results) + len(marketaux_results) + len(newsapi_results) + len(newsdata_results) + len(vantage_results)
82
 
83
+ bezinga_positives = []
84
+ bezinga_negatives = []
85
+
86
+ finhub_positives = []
87
+ finhub_negatives = []
88
+
89
+ marketaux_positives = []
90
+ marketaux_negatives = []
91
+
92
+ newsapi_positives = []
93
+ newsapi_negatives = []
94
+
95
+ newsdata_positives = []
96
+ newsdata_negatives = []
97
+
98
+ vantage_positives = []
99
+ vantage_negatives = []
100
+
101
  try:
102
  replace_values(bezinga_results)
103
 
104
  bezinga_label_mean = float(sum(d['label'] for d in bezinga_results)) / len(bezinga_results)
105
 
106
+
 
107
 
108
  for dict in bezinga_results:
109
  if dict["label"] == 2:
 
120
  print(e)
121
 
122
  # finhub
123
+ if len(finhub_results) > 0:
124
  replace_values(finhub_results)
125
 
126
  finhub_label_mean = float(sum(d['label'] for d in finhub_results)) / len(finhub_results)
127
 
128
+
 
129
 
130
  for dict in finhub_results:
131
  if dict["label"] == 2:
 
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:
 
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:
162
  replace_values(newsapi_results)
163
 
164
  newsapi_label_mean = float(sum(d['label'] for d in newsapi_results) + 1) / (len(newsapi_results) + 2)
 
 
 
165
 
166
  for dict in newsapi_results:
167
  if dict["label"] == 2:
 
177
 
178
 
179
  # newsdata
180
+ if len(newsdata_results) > 0:
181
  replace_values(newsdata_results)
182
 
183
  newsdata_label_mean = float(sum(d['label'] for d in newsdata_results)) / len(newsdata_results)
 
 
 
184
 
185
  for dict in newsdata_results:
186
  if dict["label"] == 2:
 
195
  newsdata_negative_score_mean = float(sum(d['score'] for d in newsdata_negatives)) / len(newsdata_negatives)
196
 
197
  # vantage
198
+ if len(vantage_results) > 0:
199
  replace_values(vantage_results)
200
 
201
  vantage_label_mean = float(sum(d['label'] for d in vantage_results)) / len(vantage_results)
 
 
 
202
 
203
  for dict in vantage_results:
204
  if dict["label"] == 2:
 
217
 
218
  results_dict = {
219
  "bezinga": {
220
+ "bezinga_articles": len(bezinga_results),
221
+ "bezinga_positives": len(bezinga_positives),
222
+ "bezinga_negatives": len(bezinga_negatives),
223
+ "bezinga_sentiment_mean": bezinga_label_mean if len(bezinga_results) > 0 else 0,
224
+ "bezinga_positive_score_mean": bezinga_positive_score_mean if len(bezinga_results) > 0 else 0,
225
+ "bezinga_negative_score_mean": bezinga_negative_score_mean if len(bezinga_results) > 0 else 0
226
  },
227
  "finhub": {
228
+ "finhub_articles": len(finhub_results),
229
+ "finhub_positives": len(finhub_positives),
230
+ "finhub_negatives": len(finhub_negatives),
231
+ "finhub_sentiment_mean": finhub_label_mean if len(finhub_results) > 0 else 0,
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),
246
+ "newsapi_negatives": len(newsapi_negatives),
247
+ "newsapi_sentiment_mean": newsapi_label_mean if len(newsapi_results) > 0 else 0,
248
+ "newsapi_positive_score_mean": newsapi_positive_score_mean if len(newsapi_results) > 0 else 0,
249
+ "newsapi_negative_score_mean": newsapi_negative_score_mean if len(newsapi_results) > 0 else 0
250
  },
251
  "newsdata": {
252
+ "newsdata_articles": len(newsdata_results),
253
+ "newsdata_positives": len(newsdata_positives),
254
+ "newsdata_negatives": len(newsdata_negatives),
255
+ "newsdata_sentiment_mean": newsdata_label_mean if len(newsdata_results) > 0 else 0,
256
+ "newsdata_positive_score_mean": newsdata_positive_score_mean if len(newsdata_results) > 0 else 0,
257
+ "newsdata_negative_score_mean": newsdata_negative_score_mean if len(newsdata_results) > 0 else 0
258
  },
259
  "vantage": {
260
+ "vantage_articles": len(vantage_results),
261
+ "vantage_positives": len(vantage_positives),
262
+ "vantage_negatives": len(vantage_negatives),
263
+ "vantage_sentiment_mean": vantage_label_mean if len(vantage_results) > 0 else 0,
264
+ "vantage_positive_score_mean": vantage_positive_score_mean if len(vantage_results) > 0 else 0,
265
+ "vantage_negative_score_mean": vantage_negative_score_mean if len(vantage_results) > 0 else 0
266
  },
267
  "total_articles": total_articles,
268
  "total_positives": total_positives,