changed the results path, added the results files to gitignore

This commit is contained in:
Marcin Hutek 2023-12-10 10:50:27 +01:00
parent 73725c68e0
commit e739dcb161
11 changed files with 61 additions and 144 deletions

4
.gitignore vendored
View File

@ -35,4 +35,6 @@ build/
.vscode/
### Mac OS ###
.DS_Store
.DS_Store
results/*

View File

@ -1 +0,0 @@
[{"cityName":"berlin","description":"overcast clouds","temperature":277.98,"pressure":999,"humidity":91},{"cityName":"tokyo","description":"clear sky","temperature":287.08,"pressure":1018,"humidity":60},{"cityName":"warsaw","description":"light snow","temperature":272.62,"pressure":1013,"humidity":89}]

View File

@ -1,40 +0,0 @@
%PDF-1.4
%âãÏÓ
2 0 obj
<</Length 160/Filter/FlateDecode>>stream
xœíϽ
Â0à=Oq¡‚ŤÖ3
º¸(d+!M+öÇ$|{ÓQȈg:Ã7œó"GIvpZ<70>l…œñ¥lÏ X²%™Æð -jÕ<6A>ˆˆ~Ù¬1^;œŽƒ€'v6€S8$m0ýdœ
³3õå. àûMY&éäŒ÷³W%£”%<25><>{lâÈzÕ¡Hš<$ü¿ýµ·'In䘻¾Î
endstream
endobj
4 0 obj
<</Type/Page/MediaBox[0 0 595 842]/Resources<</Font<</F1 1 0 R>>>>/Contents 2 0 R/Parent 3 0 R>>
endobj
1 0 obj
<</Type/Font/Subtype/Type1/BaseFont/Helvetica/Encoding/WinAnsiEncoding>>
endobj
3 0 obj
<</Type/Pages/Count 1/Kids[4 0 R]>>
endobj
5 0 obj
<</Type/Catalog/Pages 3 0 R>>
endobj
6 0 obj
<</Producer(iText® 5.5.13 ©2000-2018 iText Group NV \(AGPL-version\))/CreationDate(D:20231209132510+01'00')/ModDate(D:20231209132510+01'00')>>
endobj
xref
0 7
0000000000 65535 f
0000000354 00000 n
0000000015 00000 n
0000000442 00000 n
0000000242 00000 n
0000000493 00000 n
0000000538 00000 n
trailer
<</Size 7/Root 5 0 R/Info 6 0 R/ID [<eda2c8983830d18d743a6f8fbe86853a><eda2c8983830d18d743a6f8fbe86853a>]>>
%iText-5.5.13
startxref
696
%%EOF

View File

@ -1,5 +0,0 @@
<ArrayList>
<item>
<cityName>vancouver</cityName><description>overcast clouds</description><temperature>275.68</temperature><pressure>1026</pressure><humidity>92</humidity></item>
<item><cityName>chicago</cityName><description>mist</description><temperature>285.39</temperature><pressure>1001</pressure><humidity>92</humidity></item>
</ArrayList>

View File

@ -1,38 +0,0 @@
%PDF-1.4
%âãÏÓ
2 0 obj
<</Length 155/Filter/FlateDecode>>stream
xœmν
Â0…á=Wñ-BI”6vtqQÈVbiÔ61?ïÞtSÈ™ÞáÎí9ÚTÀp\" %as¬<73>~GE§Ã§<C383>I8/¦%$ƒÿh!•ïœ¶A±<E280BA>3O5B÷2Qú,j°Ê‰<10>jO×hMWl¥Ö)ïgןEã:ëú8h™n¶¤v$kÊÌ~à<>£ úÚ-DÏ
endstream
endobj
4 0 obj
<</Type/Page/MediaBox[0 0 595 842]/Resources<</Font<</F1 1 0 R>>>>/Contents 2 0 R/Parent 3 0 R>>
endobj
1 0 obj
<</Type/Font/Subtype/Type1/BaseFont/Helvetica/Encoding/WinAnsiEncoding>>
endobj
3 0 obj
<</Type/Pages/Count 1/Kids[4 0 R]>>
endobj
5 0 obj
<</Type/Catalog/Pages 3 0 R>>
endobj
6 0 obj
<</Producer(iText® 5.5.13 ©2000-2018 iText Group NV \(AGPL-version\))/CreationDate(D:20231209234439+01'00')/ModDate(D:20231209234439+01'00')>>
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
<</Size 7/Root 5 0 R/Info 6 0 R/ID [<1a7833db80448a42cbb4cd49ff42f716><1a7833db80448a42cbb4cd49ff42f716>]>>
%iText-5.5.13
startxref
691
%%EOF

View File

@ -1 +0,0 @@
[{"cityName":"warsaw","description":"broken clouds","temperature":273.31,"pressure":1007,"humidity":89}]

View File

@ -1 +0,0 @@
<ArrayList><item><cityName>chicago</cityName><description>clear sky</description><temperature>279.1</temperature><pressure>1012</pressure><humidity>62</humidity></item></ArrayList>

View File

@ -1,41 +1,41 @@
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();
}
}
}
//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();
// }
// }
//}

View File

@ -54,7 +54,7 @@ public class weatherForecast {
xmlMapper.writeValue(new File(outputFile), allEntries);
}
public static void convertToPdf(String inputFile, String outputFile) {
public static void saveToPdf(String inputFile, String outputFile) {
try (BufferedReader br = new BufferedReader(new FileReader(inputFile))) {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(outputFile));

View File

@ -87,25 +87,26 @@ public class Main {
} else if (Objects.equals(input, "z")) {
System.out.println("W jakim formacie chcesz zapisac wyniki?\n pdf/json/xml");
String whichFormat = scanner.nextLine().toLowerCase();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HHmmss");
String sformatowanyCzas = czas.format(formatter);
if (Objects.equals(whichFormat, "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" ;
String outputFile = "results/results" + sformatowanyCzas + ".pdf" ;
// System.out.println(sformatowanyCzas);
// System.out.println(outputFile);
weatherForecast.convertToPdf(temporaryFile.FILE_NAME, outputFile);
weatherForecast.saveToPdf(temporaryFile.FILE_NAME, outputFile);
} else if (Objects.equals(whichFormat, "json")) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HHmmss");
String sformatowanyCzas = czas.format(formatter);
String outputFile = "results" + sformatowanyCzas + ".json";
// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HHmmss");
// String sformatowanyCzas = czas.format(formatter);
String outputFile = "results/results" + sformatowanyCzas + ".json";
weatherForecast.saveToJson(outputFile);
} else if (Objects.equals(whichFormat, "xml")) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HHmmss");
String sformatowanyCzas = czas.format(formatter);
String outputFile = "results" + sformatowanyCzas + ".xml";
// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HHmmss");
// String sformatowanyCzas = czas.format(formatter);
String outputFile = "results/results" + sformatowanyCzas + ".xml";
weatherForecast.saveToXml(outputFile);
} else {
System.out.println("Wprowadz poprawna opcje.");

View File

@ -1,6 +1,6 @@
city: chicago
description: clear sky
temperature[K]: 279,10
pressure[hPa]: 1012
humidity[%]: 62
city: warsaw
description: broken clouds
temperature[K]: 272,49
pressure[hPa]: 1006
humidity[%]: 87
--------------------