ImportData
This commit is contained in:
parent
8f554b3936
commit
e9704d438e
4 changed files with 81 additions and 17 deletions
|
|
@ -6,14 +6,12 @@
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="org.apache.maven.plugins:maven-surefire-plugin:2.22.2" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.7.0" level="project" />
|
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.7.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.0" level="project" />
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.7.0" level="project" />
|
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.7.0" level="project" />
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.7.0" level="project" />
|
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.7.0" level="project" />
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
|
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ public class DataCsv {
|
||||||
* La methode de recuperation dun fichier csv
|
* La methode de recuperation dun fichier csv
|
||||||
*/
|
*/
|
||||||
public void getCsv(String fileZip) throws IOException{
|
public void getCsv(String fileZip) throws IOException{
|
||||||
|
//"src/main/resources/loto_201911.zip"
|
||||||
File desDir = new File("src/main/resources/");
|
File desDir = new File("src/main/resources/");
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[1024];
|
||||||
ZipInputStream zis = new ZipInputStream(new FileInputStream(fileZip));
|
ZipInputStream zis = new ZipInputStream(new FileInputStream(fileZip));
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,20 @@
|
||||||
package fr.myny.data;
|
package fr.myny.data;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
|
||||||
public class ImportData {
|
public class ImportData {
|
||||||
String url;
|
|
||||||
|
protected String url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Le constructeur de ImportData
|
* Le constructeur de ImportData
|
||||||
*/
|
*/
|
||||||
public ImportData(){
|
ImportData(){
|
||||||
|
this.url = "https://www.fdj.fr/jeux-de-tirage/loto/statistiques";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
|
|
@ -17,13 +23,76 @@ public class ImportData {
|
||||||
this.url=url;
|
this.url=url;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private boolean UrlExist() {
|
||||||
* La methode de recuperation de l URL
|
try {
|
||||||
*/
|
URL site = new URL(url);
|
||||||
public void getUrl(){
|
try {
|
||||||
|
site.openStream();
|
||||||
|
return true;
|
||||||
|
} catch (IOException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unzip() {
|
private boolean ZipNotExist(String filename) {
|
||||||
|
File directory = new File("src/main/java/resources/");
|
||||||
|
File[] files = directory.listFiles();
|
||||||
|
for (File f : files) {
|
||||||
|
if (f.getName().equals(filename))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DownloadCsvZip() {
|
||||||
|
if (UrlExist()) {
|
||||||
|
BufferedReader in = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
URL site = new URL(url);
|
||||||
|
in = new BufferedReader(new InputStreamReader(site.openStream()));
|
||||||
|
|
||||||
|
String test = "loto_";
|
||||||
|
String nameZip;
|
||||||
|
String urlZipLink;
|
||||||
|
while ((urlZipLink = in.readLine()) != null) {
|
||||||
|
if (urlZipLink.length() > 128) {
|
||||||
|
if (test.equals(urlZipLink.substring(50, 55))) {
|
||||||
|
nameZip = urlZipLink.substring(50,65);
|
||||||
|
urlZipLink = urlZipLink.substring(13,65);
|
||||||
|
if (ZipNotExist(nameZip)) {
|
||||||
|
try (BufferedInputStream bis = new BufferedInputStream(new URL(urlZipLink).openStream());
|
||||||
|
FileOutputStream fos = new FileOutputStream("src/main/java/resources/" + nameZip)) {
|
||||||
|
byte data[] = new byte[1024];
|
||||||
|
int byteContent;
|
||||||
|
while ((byteContent = bis.read(data, 0, 1024)) != -1) {
|
||||||
|
fos.write(data, 0, byteContent);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace(System.out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
in.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error URL can't open : " + e);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
in.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error close buffer : " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
System.out.println("Web sit don't exist");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,6 @@ package fr.myny.gui;
|
||||||
|
|
||||||
|
|
||||||
public class Ihm {
|
public class Ihm {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Le constructeur de Ihm
|
* Le constructeur de Ihm
|
||||||
*/
|
*/
|
||||||
|
|
@ -30,7 +27,7 @@ public class Ihm {
|
||||||
* La methode de demande de telechargement de donnees
|
* La methode de demande de telechargement de donnees
|
||||||
*/
|
*/
|
||||||
public void downloadData(){
|
public void downloadData(){
|
||||||
|
// Envoie directement l'utilisateur vers le site de téléchargement
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Reference in a new issue