// sucht zu einem Ticker die Nachrichten
function TNews.Suche_NewsZu(Ticker: string; abDatum, bisDatum: TDate): string;
var URL, Response: string;
HttpClient: TFPHTTPClient;
JsonResponse: TJSONData;
ts_ab, ts_bis: Int64;
s_from, s_to: string;
begin
Result := '';
ts_ab := DateTimeToUnix(abDatum);
ts_bis := DateTimeToUnix(bisDatum + 1); // period2 ist exklusiv!
s_from := IntToStr(ts_ab);
s_to := IntToStr(ts_bis); // brauche ich offenbar nicht, kam von Yahoo-Vorlage
URL := 'https://newsapi.org/v2/everything?q=' + Ticker +
'&from=' + s_from + '&sortBy=publishedAt&apiKey='+ APIKEY_News;
HttpClient := TFPHTTPClient.Create(nil);
HttpClient.AddHeader('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36');
try
try
Response := HttpClient.Get(URL);
except
on E: EHttpClient do
begin
case HttpClient.ResponseStatusCode of
401: Caption := 'Unauthorised';
404: Caption := 'Not found';
else
Caption := Format('error: %d', [HttpClient.ResponseStatusCode]);
end;
end;
end;
JsonResponse := GetJSON(Response);
Ersetze.JsonWirdDatei(JsonResponse, 'myNews_json'); // ich speichere es einmal ab
result:=JsonResponse.FormatJSON([]);
result:=VerarbeiteArtikel(result); //VerarbeiteAntwort(result);
finally
HttpClient.Free;
end;
end;