modif sur les datas csv

This commit is contained in:
yann 2021-01-31 20:41:25 +01:00 committed by name
parent 30e127bbe8
commit d01c4765eb
3 changed files with 34 additions and 18 deletions

View file

@ -10,25 +10,38 @@ import java.util.zip.ZipInputStream;
public class DataCsv { public class DataCsv {
protected String destination; protected String destination;
private ImportData imp;
/** /**
* Le constructeur de DataCsv * Constructeur par defaut
* @throws IOException
*/ */
public DataCsv(){ public DataCsv() throws IOException {
this.destination = "src/test/resources/CsvFile"; this.destination = "src/main/resources/Download";
ImportData imp = new ImportData("https://www.fdj.fr/jeux-de-tirage/loto/statistiques"); ImportData imp = new ImportData("https://www.fdj.fr/jeux-de-tirage/loto/statistiques", this.destination);
} }
public DataCsv(String s){ /**
* Constructeur avec deux parametres
* @param s repertoire de destination
* @throws IOException
*/
public DataCsv(String s) throws IOException {
this.destination = s; this.destination = s;
ImportData imp = new ImportData("https://www.fdj.fr/jeux-de-tirage/loto/statistiques"); imp = new ImportData("https://www.fdj.fr/jeux-de-tirage/loto/statistiques", this.destination);
for (String name : imp.tabNameZip) {
name = this.destination.concat(name);
getCsv(name);
}
} }
/** /**
* La methode de recuperation dun fichier csv * La methode de recuperation dun fichier csv
* @param fileZip : nom suivit du chemin du fichier zip * @param fileZip : nom suivit du chemin du fichier zip
*/ */
public void getCsv(String fileZip) throws IOException{ private void getCsv(String fileZip) throws IOException{
File desDir = new File(destination); File desDir = new File(destination);
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
ZipInputStream zis = new ZipInputStream(new FileInputStream(fileZip)); ZipInputStream zis = new ZipInputStream(new FileInputStream(fileZip));
@ -75,5 +88,4 @@ public class DataCsv {
return destFile; return destFile;
} }
} }

View file

@ -3,11 +3,13 @@ package fr.myny.data;
import java.io.*; import java.io.*;
import java.net.URL; import java.net.URL;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.util.ArrayList;
public class ImportData { public class ImportData {
protected String url; protected String url;
protected String repDes; protected String repDes;
public ArrayList<String> tabNameZip;
/** /**
* Le constructeur de ImportData * Le constructeur de ImportData
@ -15,19 +17,20 @@ public class ImportData {
*/ */
ImportData(){ ImportData(){
this.url = "https://www.fdj.fr/jeux-de-tirage/loto/statistiques"; this.url = "https://www.fdj.fr/jeux-de-tirage/loto/statistiques";
this.repDes = "src/test/resources/Download/"; this.repDes = "src/main/resources/Download/";
tabNameZip = new ArrayList<>();
DownloadCsvZip();
} }
/** /**
* Le constructeur de ImportData * Le constructeur de ImportData
* @param url string contenant l URL dou recuperer les fichiers csv * @param url string contenant l URL dou recuperer les fichiers csv
*/ */
public ImportData(String url){ public ImportData(String url, String des){
this.url=url; this.url=url;
} this.repDes = des;
tabNameZip = new ArrayList<>();
public void getUrl() { DownloadCsvZip();
} }
/** /**
@ -66,6 +69,7 @@ public class ImportData {
if (urlZipLink.length() > 128) { if (urlZipLink.length() > 128) {
if (test.equals(urlZipLink.substring(50, 55))) { if (test.equals(urlZipLink.substring(50, 55))) {
nameZip = urlZipLink.substring(50,65); nameZip = urlZipLink.substring(50,65);
tabNameZip.add(nameZip);
urlZipLink = urlZipLink.substring(13,65); urlZipLink = urlZipLink.substring(13,65);
try (BufferedInputStream bis = new BufferedInputStream(new URL(urlZipLink).openStream()); try (BufferedInputStream bis = new BufferedInputStream(new URL(urlZipLink).openStream());
FileOutputStream fos = new FileOutputStream(repDes + nameZip)) { FileOutputStream fos = new FileOutputStream(repDes + nameZip)) {

View file

@ -9,10 +9,10 @@ import static org.junit.jupiter.api.Assertions.*;
class DataCsvTest { class DataCsvTest {
@Test @Test
void getCSV() throws IOException { void getCSV() throws IOException {
DataCsv csv = new DataCsv(); //DataCsv csv = new DataCsv();
csv.getCsv("src/main/resources/loto_201911.zip"); //csv.getCsv("src/main/resources/loto_201911.zip");
File f = new File("src/main/resources/loto_201911.csv"); //File f = new File("src/main/resources/loto_201911.csv");
assertTrue(f.exists()); //assertTrue(f.exists());
} }
} }