From 73725c68e01384319c305c076899edbd6fa51427 Mon Sep 17 00:00:00 2001 From: Marcin Hutek Date: Sat, 9 Dec 2023 23:46:48 +0100 Subject: [PATCH] feature that adds date and time to the results file created --- results2023-12-09_234435.pdf | 38 +++++++++++++++++++++++++++++ results2023-12-09_234517.json | 1 + results2023-12-09_234531.xml | 1 + src/main/java/org/example/Main.java | 21 ++++++++++++---- temporary_file.txt | 20 +++------------ 5 files changed, 60 insertions(+), 21 deletions(-) create mode 100644 results2023-12-09_234435.pdf create mode 100644 results2023-12-09_234517.json create mode 100644 results2023-12-09_234531.xml diff --git a/results2023-12-09_234435.pdf b/results2023-12-09_234435.pdf new file mode 100644 index 0000000..122a8ef --- /dev/null +++ b/results2023-12-09_234435.pdf @@ -0,0 +1,38 @@ +%PDF-1.4 +% +2 0 obj +<>stream +xmν +0=W-BI6vtqQVbi61?tSș9Tp\" %as~GEçI8/%$h!A3O5B2Q,jʉjOhMWl)gןE:8hnv$k~ -D +endstream +endobj +4 0 obj +<>>>/Contents 2 0 R/Parent 3 0 R>> +endobj +1 0 obj +<> +endobj +3 0 obj +<> +endobj +5 0 obj +<> +endobj +6 0 obj +<> +endobj +xref +0 7 +0000000000 65535 f +0000000349 00000 n +0000000015 00000 n +0000000437 00000 n +0000000237 00000 n +0000000488 00000 n +0000000533 00000 n +trailer +<<1a7833db80448a42cbb4cd49ff42f716>]>> +%iText-5.5.13 +startxref +691 +%%EOF diff --git a/results2023-12-09_234517.json b/results2023-12-09_234517.json new file mode 100644 index 0000000..9d52c74 --- /dev/null +++ b/results2023-12-09_234517.json @@ -0,0 +1 @@ +[{"cityName":"warsaw","description":"broken clouds","temperature":273.31,"pressure":1007,"humidity":89}] \ No newline at end of file diff --git a/results2023-12-09_234531.xml b/results2023-12-09_234531.xml new file mode 100644 index 0000000..86ba86d --- /dev/null +++ b/results2023-12-09_234531.xml @@ -0,0 +1 @@ +chicagoclear sky279.1101262 \ No newline at end of file diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java index b1382c1..2ca950c 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -12,6 +12,9 @@ import model.*; import java.io.IOException; import java.util.*; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; //import java.io.File; //import java.io.IOException; //import java.sql.SQLOutput; @@ -38,6 +41,8 @@ public class Main { CityNames cityNames = new CityNames(); cityNames.cityNamesRead(fileCities); + LocalDateTime czas = LocalDateTime.now(); + Scanner scanner = new Scanner(System.in); TemporaryFile temporaryFile = new TemporaryFile(); @@ -83,18 +88,24 @@ public class Main { System.out.println("W jakim formacie chcesz zapisac wyniki?\n pdf/json/xml"); String whichFormat = scanner.nextLine().toLowerCase(); if (Objects.equals(whichFormat, "pdf")) { - String outputFile = "results.pdf"; // ConvertResultPdf convertResult = new ConvertResultPdf(temporaryFile.FILE_NAME, // "results.pdf"); // convertResult.convertToPdf(); - + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HHmmss"); + String sformatowanyCzas = czas.format(formatter); + String outputFile = "results" + sformatowanyCzas + ".pdf" ; +// System.out.println(sformatowanyCzas); +// System.out.println(outputFile); weatherForecast.convertToPdf(temporaryFile.FILE_NAME, outputFile); - } else if (Objects.equals(whichFormat, "json")) { - String outputFile = "results.json"; + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HHmmss"); + String sformatowanyCzas = czas.format(formatter); + String outputFile = "results" + sformatowanyCzas + ".json"; weatherForecast.saveToJson(outputFile); } else if (Objects.equals(whichFormat, "xml")) { - String outputFile = "results.xml"; + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HHmmss"); + String sformatowanyCzas = czas.format(formatter); + String outputFile = "results" + sformatowanyCzas + ".xml"; weatherForecast.saveToXml(outputFile); } else { System.out.println("Wprowadz poprawna opcje."); diff --git a/temporary_file.txt b/temporary_file.txt index 8c2b575..75c379d 100644 --- a/temporary_file.txt +++ b/temporary_file.txt @@ -1,18 +1,6 @@ city: chicago -description: light rain -temperature[K]: 285,44 -pressure[hPa]: 1001 -humidity[%]: 92 --------------------- -city: chicago -description: light rain -temperature[K]: 285,44 -pressure[hPa]: 1001 -humidity[%]: 92 --------------------- -city: chicago -description: light rain -temperature[K]: 285,44 -pressure[hPa]: 1001 -humidity[%]: 92 +description: clear sky +temperature[K]: 279,10 +pressure[hPa]: 1012 +humidity[%]: 62 --------------------