-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding ability to export csv form of either task or wallet
- Loading branch information
1 parent
34d36d1
commit 05d83bd
Showing
4 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#Fri Nov 08 15:37:50 SGT 2019 | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-all.zip | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package executor.command; | ||
|
||
import com.opencsv.CSVWriter; | ||
import duke.exception.DukeException; | ||
import storage.StorageManager; | ||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.util.Scanner; | ||
|
||
public class CommandExport extends Command { | ||
|
||
private String filePath; | ||
|
||
public CommandExport(String userInput) { | ||
this.userInput = userInput; | ||
this.commandType = CommandType.EXPORT; | ||
this.description = "Exports txt into CSV" | ||
+ "FORMAT : export <wallet or task>"; | ||
} | ||
|
||
@Override | ||
public void execute(StorageManager storageManager) { | ||
|
||
} | ||
|
||
public void convertTxtToCsv(String data) throws DukeException { | ||
if(data.toLowerCase().equals("wallet")){ | ||
this.filePath = "savedWallet.txt"; | ||
} else { | ||
this.filePath = "savedTask.txt"; | ||
} | ||
try{ | ||
File file = new File(this.filePath); | ||
Scanner scanner = new Scanner(file); | ||
while (scanner.hasNextLine()) { | ||
String loadedInput = scanner.nextLine(); | ||
if (loadedInput.equals("")) { | ||
break; | ||
} | ||
writeCSV(loadedInput); | ||
} | ||
} catch (Exception e) { | ||
throw new DukeException("No Previously Saved Wallet Data."); | ||
} | ||
} | ||
|
||
|
||
private void writeCSV(String line) throws DukeException { | ||
// first create file object for file placed at location | ||
// specified by filepath | ||
File file = new File("data.csv"); | ||
try { | ||
// create FileWriter object with file as parameter | ||
FileWriter outputFile = new FileWriter(file); | ||
// create CSVWriter object filewriter object as parameter | ||
CSVWriter writer = new CSVWriter(outputFile); | ||
// add data to csv | ||
String[] eachRowOfData = {line.replace(" ", ",")}; | ||
writer.writeNext(eachRowOfData); | ||
// closing writer connection | ||
writer.close(); | ||
} | ||
catch (IOException e) { | ||
throw new DukeException("Unable to convert txt into csv"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters