-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated to collect BBC News' top story. Also fixed issue with weather…
… parsing where inline ',' would cause errors.
- Loading branch information
1 parent
4b4ae6c
commit 1d9289e
Showing
6 changed files
with
37 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,37 @@ | ||
package curtains; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
import org.apache.http.client.fluent.Request; | ||
|
||
public class News { | ||
|
||
public String getNews() throws IOException { | ||
|
||
String newsPage = "http://newsapi.org/v2/top-headlines?" + "pageSize=1&" | ||
// today's news | ||
String todaysNewsPage = "https://newsapi.org/v2/top-headlines?" + "pageSize=1&" | ||
+ "sources=bbc-news&" + "apiKey=" + Config.NEWSAPI_KEY; | ||
|
||
return "Test"; | ||
String todaysNewsJson = Request | ||
.Get(URI.create(todaysNewsPage)) | ||
.execute() | ||
.returnContent().asString(); | ||
|
||
JsonNode todaysNewsObj = Config.MAPPER.readTree(todaysNewsJson); | ||
|
||
// historical news | ||
// https://content.guardianapis.com/search?q=12%20years%20a%20slave&format=json&tag=film/film,tone/reviews&from-date=2010-01-01&show-tags=contributor&show-fields=starRating,headline,thumbnail,short-url&order-by=relevance&api-key=test | ||
String historicalNewsPage = "https://content.guardianapis.com/search?" + "pageSize=1&" | ||
+ "api-key=" + Config.GUARDIAN_OPEN_PLATFORM_API_KEY; | ||
|
||
if (todaysNewsObj.findValue("status").asText().equals("ok")) { | ||
|
||
JsonNode topArticle = todaysNewsObj.findValues("articles").get(0); | ||
return topArticle.findValue("title").asText() + ": " + topArticle.findValue("url").asText(); | ||
|
||
} else { | ||
return "Error retrieving news"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters