Main.java cleared and commented out
This commit is contained in:
parent
8eab3cd07c
commit
dfeb251d16
2
.gitignore
vendored
2
.gitignore
vendored
@ -36,3 +36,5 @@ build/
|
|||||||
|
|
||||||
### Mac OS ###
|
### Mac OS ###
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
temporary_file.txt
|
41
results/.gitignore
vendored
Normal file
41
results/.gitignore
vendored
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
!**/src/main/**/target/
|
||||||
|
!**/src/test/**/target/
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea/modules.xml
|
||||||
|
.idea/jarRepositories.xml
|
||||||
|
.idea/compiler.xml
|
||||||
|
.idea/libraries/
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
### Eclipse ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
build/
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
### Mac OS ###
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
*
|
||||||
|
!.gitignore
|
@ -1,41 +0,0 @@
|
|||||||
//package model;
|
|
||||||
//import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
//import com.itextpdf.text.Document;
|
|
||||||
//import com.itextpdf.text.Paragraph;
|
|
||||||
//import com.itextpdf.text.pdf.PdfWriter;
|
|
||||||
//
|
|
||||||
//import java.io.BufferedReader;
|
|
||||||
//import java.io.FileOutputStream;
|
|
||||||
//import java.io.FileReader;
|
|
||||||
//import java.io.IOException;
|
|
||||||
//import java.util.List;
|
|
||||||
//
|
|
||||||
//public class ConvertResultPdf {
|
|
||||||
// private String inputFile;
|
|
||||||
// private String outputFile;
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// public ConvertResultPdf(String inputFile, String outputFile) {
|
|
||||||
// this.inputFile = inputFile;
|
|
||||||
// this.outputFile = outputFile;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void convertToPdf() {
|
|
||||||
// try (BufferedReader br = new BufferedReader(new FileReader(inputFile))) {
|
|
||||||
// Document document = new Document();
|
|
||||||
// PdfWriter.getInstance(document, new FileOutputStream(outputFile));
|
|
||||||
// document.open();
|
|
||||||
//
|
|
||||||
// String line;
|
|
||||||
// while ((line = br.readLine()) != null) {
|
|
||||||
// document.add(new Paragraph(line));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// document.close();
|
|
||||||
// } catch (IOException e) {
|
|
||||||
// e.printStackTrace();
|
|
||||||
// } catch (Exception e) {
|
|
||||||
// e.printStackTrace();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
@ -1,32 +1,15 @@
|
|||||||
package org.example;
|
package org.example;
|
||||||
|
|
||||||
//import com.fasterxml.jackson.core.type.TypeReference;
|
|
||||||
//import com.fasterxml.jackson.databind.JsonNode;
|
|
||||||
//import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import model.*;
|
import model.*;
|
||||||
//import org.apache.http.client.ClientProtocolException;
|
|
||||||
//import org.apache.http.client.methods.CloseableHttpResponse;
|
|
||||||
//import org.apache.http.client.methods.HttpUriRequest;
|
|
||||||
//import org.apache.http.impl.client.CloseableHttpClient;
|
|
||||||
//import org.apache.http.impl.client.CookieSpecRegistries;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
//import java.io.File;
|
|
||||||
//import java.io.IOException;
|
|
||||||
//import java.sql.SQLOutput;
|
|
||||||
//import java.util.List;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
//import org.apache.http.Header;
|
|
||||||
//import org.apache.http.HttpEntity;
|
|
||||||
//import org.apache.http.HttpResponse;
|
|
||||||
//import org.apache.http.client.methods.HttpGet;
|
|
||||||
//import org.apache.http.impl.client.HttpClients;
|
|
||||||
//import org.apache.http.util.EntityUtils;
|
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
@ -34,6 +17,7 @@ public class Main {
|
|||||||
String API_key = "4c991761f17e10358c944a3c64a3e24c";
|
String API_key = "4c991761f17e10358c944a3c64a3e24c";
|
||||||
String fileCities = "cities.json";
|
String fileCities = "cities.json";
|
||||||
|
|
||||||
|
// utworzenie listy miast wraz z ich koordynatami
|
||||||
JsonToMap jsonToMap = new JsonToMap();
|
JsonToMap jsonToMap = new JsonToMap();
|
||||||
Map<String, Map<String, Double>> cityMap =
|
Map<String, Map<String, Double>> cityMap =
|
||||||
jsonToMap.createCityMap(fileCities);
|
jsonToMap.createCityMap(fileCities);
|
||||||
@ -45,67 +29,70 @@ public class Main {
|
|||||||
|
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
|
// utworzenie pustego pliku tymczasowego przechowujacego wyniki zapytan
|
||||||
TemporaryFile temporaryFile = new TemporaryFile();
|
TemporaryFile temporaryFile = new TemporaryFile();
|
||||||
temporaryFile.createEmptyFile();
|
temporaryFile.createEmptyFile();
|
||||||
|
|
||||||
|
|
||||||
HttpClient httpClient = new HttpClient();
|
HttpClient httpClient = new HttpClient();
|
||||||
// ForecastPreparation weatherString = new ForecastPreparation();
|
|
||||||
ForecastPreparation forecastPreparation = new ForecastPreparation();
|
ForecastPreparation forecastPreparation = new ForecastPreparation();
|
||||||
System.out.println("Program rozpoczal dzialanie.");
|
System.out.println("Program rozpoczal dzialanie.");
|
||||||
|
|
||||||
|
|
||||||
|
// glowna petla programu
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
System.out.println("Sprawdz pogode - y \n" +
|
System.out.println("Sprawdz pogode - y \n" +
|
||||||
"Zakoncz i zapisz wynik - z\n" +
|
"Zakoncz i zapisz wynik - z\n" +
|
||||||
"Wyjdz bez zapisywania - x");
|
"Wyjdz bez zapisywania - x");
|
||||||
String input = scanner.nextLine().toLowerCase();
|
String input = scanner.nextLine().toLowerCase();
|
||||||
|
|
||||||
|
// wyswietlenie prognozy dla wskazanego miasta
|
||||||
if (Objects.equals(input, "y")) {
|
if (Objects.equals(input, "y")) {
|
||||||
System.out.println("Podaj nazwe miasta: ");
|
System.out.println("Podaj nazwe miasta: ");
|
||||||
String inputCity = scanner.nextLine().toLowerCase();
|
String inputCity = scanner.nextLine().toLowerCase();
|
||||||
if (cityMap.containsKey(inputCity)) {
|
if (cityMap.containsKey(inputCity)) {
|
||||||
|
|
||||||
Map<String, Double> specificCity = (Map<String, Double>) cityMap.get(inputCity);
|
Map<String, Double> specificCity = (Map<String, Double>) cityMap.get(inputCity);
|
||||||
double latitude = (double) specificCity.get("latitude");
|
double latitude = (double) specificCity.get("latitude");
|
||||||
double longitude = (double) specificCity.get("longitude");
|
double longitude = (double) specificCity.get("longitude");
|
||||||
|
|
||||||
|
// wygenerowanie odpowiedniego adresu url
|
||||||
String urlString = "https://api.openweathermap.org/data/2.5/weather?lat=" + latitude +
|
String urlString = "https://api.openweathermap.org/data/2.5/weather?lat=" + latitude +
|
||||||
"&lon=" + longitude + "&appid=" + API_key;
|
"&lon=" + longitude + "&appid=" + API_key;
|
||||||
|
|
||||||
String response = httpClient.executeGetRequest(urlString);
|
String response = httpClient.executeGetRequest(urlString);
|
||||||
// System.out.println(response);]
|
|
||||||
|
|
||||||
weatherForecast weatherForecast = forecastPreparation.fetchForecastData(inputCity, response);
|
weatherForecast weatherForecast = forecastPreparation.fetchForecastData(inputCity, response);
|
||||||
|
|
||||||
String forecastString = weatherForecast.prepareForecastString();
|
String forecastString = weatherForecast.prepareForecastString();
|
||||||
System.out.println(forecastString);
|
System.out.println(forecastString);
|
||||||
// String forecastString = weatherString.prepareForecast(inputCity, response);
|
|
||||||
// System.out.println(forecastString);
|
// zapisanie prognozy do pliku tymczasowego
|
||||||
temporaryFile.addToFile(forecastString);
|
temporaryFile.addToFile(forecastString);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Podanego miasta nie ma na liscie.");
|
System.out.println("Podanego miasta nie ma na liscie.");
|
||||||
}
|
}
|
||||||
|
// zapis wynikow
|
||||||
} else if (Objects.equals(input, "z")) {
|
} else if (Objects.equals(input, "z")) {
|
||||||
|
|
||||||
System.out.println("W jakim formacie chcesz zapisac wyniki?\n pdf/json/xml");
|
System.out.println("W jakim formacie chcesz zapisac wyniki?\n pdf/json/xml");
|
||||||
String whichFormat = scanner.nextLine().toLowerCase();
|
String whichFormat = scanner.nextLine().toLowerCase();
|
||||||
|
|
||||||
|
// odczyt czasu na potrzeby wygenerowania nazwy pliku
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HHmmss");
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HHmmss");
|
||||||
String sformatowanyCzas = czas.format(formatter);
|
String sformatowanyCzas = czas.format(formatter);
|
||||||
if (Objects.equals(whichFormat, "pdf")) {
|
|
||||||
// ConvertResultPdf convertResult = new ConvertResultPdf(temporaryFile.FILE_NAME,
|
|
||||||
// "results.pdf");
|
|
||||||
// convertResult.convertToPdf();
|
|
||||||
|
|
||||||
|
// zapis do pdf
|
||||||
|
if (Objects.equals(whichFormat, "pdf")) {
|
||||||
String outputFile = "results/results" + sformatowanyCzas + ".pdf" ;
|
String outputFile = "results/results" + sformatowanyCzas + ".pdf" ;
|
||||||
// System.out.println(sformatowanyCzas);
|
|
||||||
// System.out.println(outputFile);
|
|
||||||
weatherForecast.saveToPdf(temporaryFile.FILE_NAME, outputFile);
|
weatherForecast.saveToPdf(temporaryFile.FILE_NAME, outputFile);
|
||||||
|
//zapis do json
|
||||||
} else if (Objects.equals(whichFormat, "json")) {
|
} else if (Objects.equals(whichFormat, "json")) {
|
||||||
// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HHmmss");
|
|
||||||
// String sformatowanyCzas = czas.format(formatter);
|
|
||||||
String outputFile = "results/results" + sformatowanyCzas + ".json";
|
String outputFile = "results/results" + sformatowanyCzas + ".json";
|
||||||
weatherForecast.saveToJson(outputFile);
|
weatherForecast.saveToJson(outputFile);
|
||||||
|
// zapis do xml
|
||||||
} else if (Objects.equals(whichFormat, "xml")) {
|
} else if (Objects.equals(whichFormat, "xml")) {
|
||||||
// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HHmmss");
|
|
||||||
// String sformatowanyCzas = czas.format(formatter);
|
|
||||||
String outputFile = "results/results" + sformatowanyCzas + ".xml";
|
String outputFile = "results/results" + sformatowanyCzas + ".xml";
|
||||||
weatherForecast.saveToXml(outputFile);
|
weatherForecast.saveToXml(outputFile);
|
||||||
} else {
|
} else {
|
||||||
@ -114,6 +101,7 @@ public class Main {
|
|||||||
}
|
}
|
||||||
System.out.println("Program zakonczyl dzialanie.");
|
System.out.println("Program zakonczyl dzialanie.");
|
||||||
break;
|
break;
|
||||||
|
// wyjscie z programu
|
||||||
} else if (Objects.equals(input,"x")) {
|
} else if (Objects.equals(input,"x")) {
|
||||||
System.out.println("Program zakonczyl dzialanie.");
|
System.out.println("Program zakonczyl dzialanie.");
|
||||||
break;
|
break;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
city: warsaw
|
city: warsaw
|
||||||
description: broken clouds
|
description: broken clouds
|
||||||
temperature[K]: 272,49
|
temperature[K]: 276,80
|
||||||
pressure[hPa]: 1006
|
pressure[hPa]: 1005
|
||||||
humidity[%]: 87
|
humidity[%]: 95
|
||||||
--------------------
|
--------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user