Skip to content

CineScribe #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
5 changes: 4 additions & 1 deletion .idea/misc.xml

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

73 changes: 28 additions & 45 deletions Report-Template.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,45 @@
# Project Title
# Movies and Actors 🎬🌟

Simple overview of use/purpose.
This program shows the detail of a movie or an actor.

## Description
## Description 📖

An in-depth paragraph about your project and overview of use.
The program collect the information from resources and shows them to you.
It has two option as well and you have select one.
"Movies and Actors" the title says it all, you just have to search them up by their names.

## Getting Started

### Dependencies

* Describe any prerequisites, libraries, OS version, etc., needed before installing program.
* ex. Windows 10
## Getting Started

### Installing
### Dependencies 🍔

* How/where to download your program
* Any modifications needed to be made to files/folders
* First of all you have to install gradle.
* the resources come from https://omdbapi.com (Movies) and https://api-ninjas.com/api/celebrity (Actors).
* the imported classes are in program as well.

### Executing program
### Installing ✅

* How to run the program
* Step-by-step bullets
```
code blocks for commands
```
* To install gradle go to https://gradle.org/install/ address, and it shows you the way to install it(I downloaded v8.6).
* Get the API key from two websites which was the resources after you made your account.

## Help
### Executing program ▶

Any advise for common problems or issues.
* Make sure your gradle works properly.
* Run the "Main" program in terminal.
* Then enter the number of the options.
```
command to run if program contains helper info
1. Movies
2. Actors
3. Exit
```

## Authors

Contributors names and contact info

ex. Dominique Pizzie
ex. [@DomPizzie](https://twitter.com/dompizzie)

## Version History

* 0.2
* Various bug fixes and optimizations
* See [commit change]() or See [release history]()
* 0.1
* Initial Release

## License
## Authors 📝

This project is licensed under the [NAME HERE] License - see the LICENSE.md file for details
**GitHub:** Soroushsbr
**Email:** soroush.13830o@gmail.com

## Acknowledgments
## Resources🧱

Inspiration, code snippets, etc.
* [awesome-readme](https://github.com/matiassingers/awesome-readme)
* [PurpleBooth](https://gist.github.com/PurpleBooth/109311bb0361f32d87a2)
* [dbader](https://github.com/dbader/readme-template)
* [zenorocha](https://gist.github.com/zenorocha/4526327)
* [fvcproductions](https://gist.github.com/fvcproductions/1bfc2d4aecb01a834b46)
* [🔗 Getting Json Data From A RESTFUL API Using Java](https://medium.com/swlh/getting-json-data-from-a-restful-api-using-java-b327aafb3751)
* [🔗 Uploading a File and JSON Data in Postman](https://www.baeldung.com/postman-upload-file-json)
* [🔗 Send API requests and get response data in Postman](https://learning.postman.com/docs/sending-requests/requests/)
33 changes: 19 additions & 14 deletions src/main/java/Actors.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import java.io.InputStreamReader;
import java.net.URL;
import java.net.HttpURLConnection;
import org.json.JSONObject;
public class Actors {
public static final String API_KEY = "Your API_KEY"; // TODO --> add your api key about Actors here
String netWorth;
Boolean isAlive;
public static final String API_KEY = "DxPDkxjUL6bpYDurOQZwiw==1IjnRq8i7CSBVRPQ";
String name;
String birthday;
double netWorth;
boolean isAlive;

public Actors(String name, boolean isAlive){

public Actors(String netWorth, boolean isAlive){
//TODO --> (Write a proper constructor using the get_from_api functions)
}
@SuppressWarnings({"deprecation"})
/**
Expand All @@ -19,22 +22,20 @@ public Actors(String netWorth, boolean isAlive){
*/
public String getActorData(String name) {
try {
URL url = new URL("https://api.api-ninjas.com/v1/celebrity?name="+
name.replace(" ", "+")+"&apikey="+API_KEY);
URL url = new URL("https://api.api-ninjas.com/v1/celebrity?name="+ name.replace(" ", "+"));
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("X-Api-Key", API_KEY);
System.out.println(connection);
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();

while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}

in.close();
return response.toString();
String result = response.toString();
return result.substring(1 ,result.length() - 1);
} else {
return "Error: " + connection.getResponseCode() + " " + connection.getResponseMessage();
}
Expand All @@ -44,21 +45,25 @@ public String getActorData(String name) {
}
}
public double getNetWorthViaApi(String actorsInfoJson){
//TODO --> (This function must return the "NetWorth")
JSONObject jsonObject = new JSONObject(actorsInfoJson);
double result = 0.0;
result = jsonObject.getDouble("net_worth");
return result;
}

public boolean isAlive(String actorsInfoJson){
//TODO --> (If your chosen actor is alive it must return true otherwise it must return false)
public static boolean isAlive(String actorsInfoJson){
boolean statues = false;
JSONObject jsonObject = new JSONObject(actorsInfoJson);
statues = jsonObject.getBoolean("is_alive");
return statues;
}

public String getDateOfDeathViaApi(String actorsInfoJson){
//TODO --> (If your chosen actor is deceased it must return the date of death) -->
String date = "";
JSONObject jsonObject = new JSONObject(actorsInfoJson);
date = jsonObject.getString("death");
return date;
}


}
30 changes: 28 additions & 2 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO --> complete main function
runMenu();
}
public static void runMenu() {
// TODO
Scanner in = new Scanner(System.in);
System.out.print("1. Movie\n2. Actor\n3. Exit\nPlease Select an Option: ");
String option = in.nextLine();
if(option.equals("1")){
System.out.print("Enter the Name of Movie: ");
String title = in.nextLine();
Movie movie = new Movie(new ArrayList<>(),"",0);
String movieInfoJson = movie.getMovieData(title);
JSONObject json = new JSONObject(movieInfoJson);
System.out.println(json.toString(4).replace("\"" , "") + "\n**********************************************************");
runMenu();
}
else if(option.equals("2")){
System.out.print("Enter the Name of Actor: ");
String name = in.nextLine();
Actors actors = new Actors("", false);
String actorsInfoJson = actors.getActorData(name);
JSONObject json = new JSONObject(actorsInfoJson);
System.out.println(json.toString(4).replace("\"" , "") + "\n**********************************************************");
runMenu();
}
else{
System.out.println("Bye^-^");
}
}
}
46 changes: 32 additions & 14 deletions src/main/java/Movie.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import org.json.JSONObject;

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.io.BufferedReader;
import java.util.ArrayList;
public class Movie {
public static final String API_KEY = "Your API_KEY"; // TODO --> add your api key about Movie here
public static final String API_KEY = "1ee38a46"; // TODO --> add your api key about Movie here
int ImdbVotes;
ArrayList<String> actorsList;
String rating;
Expand All @@ -22,35 +25,50 @@ public Movie(ArrayList<String> actorsList, String rating, int ImdbVotes){
* @return a string representation of the MovieData, or null if an error occurred
*/

public String getMovieData(String title) throws IOException {
URL url = new URL("https://www.omdbapi.com/?t="+title+"&apikey="+API_KEY);
URLConnection Url = url.openConnection();
Url.setRequestProperty("Authorization", "Key" + API_KEY);
BufferedReader reader = new BufferedReader(new InputStreamReader(Url.getInputStream()));
String line;
StringBuilder stringBuilder = new StringBuilder();
while ((line = reader.readLine())!=null) {
stringBuilder.append(line);
public String getMovieData(String title) {
try {
URL url = new URL("https://www.omdbapi.com/?t=" + title.replace(" ", "+") + "&apikey=" + API_KEY);
URLConnection Url = url.openConnection();
Url.setRequestProperty("Authorization", "Key" + API_KEY);
if(((HttpURLConnection) Url).getResponseCode() == HttpURLConnection.HTTP_OK) {
BufferedReader reader = new BufferedReader(new InputStreamReader(Url.getInputStream()));
String line;
StringBuilder stringBuilder = new StringBuilder();
while ((line = reader.readLine()) != null) {
stringBuilder.append(line);
}
reader.close();
return stringBuilder.toString();
}
else {
return "Error: " + ((HttpURLConnection) Url).getResponseCode() + " " + ((HttpURLConnection) Url).getResponseMessage();
}
}catch (IOException e) {
e.printStackTrace();
return null;
}
reader.close();
//handle an error if the chosen movie is not found
return stringBuilder.toString();

}
public int getImdbVotesViaApi(String moviesInfoJson){
//TODO --> (This function must change and return the "ImdbVotes" as an Integer)
// NOTICE :: you are not permitted to convert this function to return a String instead of an int !!!
int ImdbVotes = 0;
JSONObject jsonObject = new JSONObject(moviesInfoJson);
ImdbVotes = Integer.parseInt((jsonObject.getString("imdbVotes").replace("," ,"")));
return ImdbVotes;
}

public String getRatingViaApi(String moviesInfoJson){
//TODO --> (This function must return the rating in the "Ratings" part
// where the source is "Internet Movie Database") -->
String rating = "";
return rating;
JSONObject jsonObject = new JSONObject(moviesInfoJson);
rating = jsonObject.getString("imdbRating");
return rating + "/10";
}

public void getActorListViaApi(String movieInfoJson){
//TODO --> (This function must return the "Actors" in actorsList)

}
}