Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/libraries/Gradle__org_json_json_20231013.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/material_theme_project_new.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/modules/BreakingNews.main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/modules/BreakingNews.test.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion BreakingNews.iml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<excludeFolder url="file://$MODULE_DIR$/BreakingNews/.gradle" />
<excludeFolder url="file://$MODULE_DIR$/BreakingNews/build" />
</content>
<orderEntry type="jdk" jdkName="23" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Binary file added BreakingNews/.gradle/8.13/checksums/checksums.lock
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file modified BreakingNews/.gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
4 changes: 2 additions & 2 deletions BreakingNews/.gradle/buildOutputCleanup/cache.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Sat Mar 01 16:55:21 GMT+03:30 2025
gradle.version=8.12.1
#Sun Jun 01 16:18:37 GMT+03:30 2025
gradle.version=8.13
Binary file modified BreakingNews/.gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
1 change: 1 addition & 0 deletions BreakingNews/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ repositories {
}

dependencies {
implementation 'org.json:json:20231013'
testImplementation platform('org.junit:junit-bom:5.9.1')
testImplementation 'org.junit.jupiter:junit-jupiter'
}
Expand Down
Binary file not shown.
Binary file modified BreakingNews/build/classes/java/main/AP/Main.class
Binary file not shown.
Binary file not shown.
Binary file modified BreakingNews/build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
64 changes: 55 additions & 9 deletions BreakingNews/src/main/java/AP/Infrastructure.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.ArrayList;
import java.util.Scanner;

import org.json.*;

public class Infrastructure {

Expand All @@ -19,6 +22,8 @@ public Infrastructure(String APIKEY) {
this.APIKEY = APIKEY;
this.URL = "https://newsapi.org/v2/everything?q=tesla&from=2025-02-05&sortBy=publishedAt&apiKey=";
this.JSONRESULT = getInformation();
this.newsList = new ArrayList<News>();
parseInformation();
}

public ArrayList<News> getNewsList() {
Expand Down Expand Up @@ -46,15 +51,56 @@ private String getInformation() {
}

private void parseInformation() {
// TODO: Get the first 20 news from the articles array of the json result
// and parse the information of each on of them to be mapped to News class
// finally add them to newsList in this class to display them in the output
}
if (JSONRESULT == null){
System.out.println("Eror ! No data to parse");
return;
}

JSONObject obj = new JSONObject(JSONRESULT);
JSONArray articles = obj.getJSONArray("articles");
int count = Math.min(articles.length(), 20);
for (int i = 0; i < count; i++) {

public void displayNewsList() {
// TODO: Display titles of the news you got from api
// and print them in a way that user can choose one
// to see the full information of the news
JSONObject article = articles.getJSONObject(i);

String title = article.optString("title" , "no title");
String author = article.optString("author" , "unknown author");
String description = article.optString("description" , "no description");
String publishedAt = article.optString("publish Date" , "unknown date");
String url = article.optString("url" , "no url");
String sourceName = article.optString("source" , "unknown source");

newsList.add(new News(title , description , author , sourceName , url , publishedAt ));
}
}

}
public void displayNewsList() throws IOException {
if(newsList.isEmpty()) {
System.out.println("there is no news to show :(");
return;
}
System.out.println("top 20 Available Articles : \n");
for(int i = 0; i < newsList.size(); i++) {
System.out.println((i + 1) + ". " + newsList.get(i).getTitle());
}
System.out.println("which article do you want to show : ");
Scanner scanner = new Scanner(System.in);
int input = scanner.nextInt();
if(input >= 1 && input <= 20) {
newsList.get(input-1).displayNews();
System.out.println("press enter to continue");
char ch = (char) System.in.read();
if(ch == '\n' || ch == '\r')
{
System.in.read();
displayNewsList();
}
else
{
System.out.println("Bye!!!");
}
}
else
System.out.println("please enter a valid number");
}
}
8 changes: 6 additions & 2 deletions BreakingNews/src/main/java/AP/Main.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package AP;

public class Main {
public static void main(String[] args) {
import java.io.IOException;

public class Main {
public static void main(String[] args) throws IOException {
String API_KEY = "e3915463e942417aba46368a2b4b7509";
Infrastructure infrastructure = new Infrastructure(API_KEY);
infrastructure.displayNewsList();
}
}
77 changes: 77 additions & 0 deletions BreakingNews/src/main/java/AP/News.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package AP;

public class News {
private String title;
private String description;
private String author;
private String sourceName;
private String url;
private String publishedAt;

public News(String title, String description, String author, String sourceName, String url, String publishedAt) {
this.title = title;
this.description = description;
this.author = author;
this.sourceName = sourceName;
this.url = url;
this.publishedAt = publishedAt;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getAuthor() {
return author;
}

public void setAuthor(String author) {
this.author = author;
}

public String getSourceName() {
return sourceName;
}

public void setSourceName(String sourceName) {
this.sourceName = sourceName;
}

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public String getPublishedAt() {
return publishedAt;
}

public void setPublishedAt(String publishedAt) {
this.publishedAt = publishedAt;
}

public void displayNews(){
System.out.println("Title: " + title);
System.out.println("Description: " + description);
System.out.println("Author: " + author);
System.out.println("Source Name: " + sourceName);
System.out.println("URL: " + url);
System.out.println("Published At: " + publishedAt);
}

}