-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
247 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package net.cofcool.toolbox; | ||
|
||
public enum ToolName { | ||
trelloLogseqImporter, shell, link2Tool, converts | ||
trelloLogseqImporter, shell, link2Tool, kindle, converts | ||
} |
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
47 changes: 47 additions & 0 deletions
47
src/main/java/net/cofcool/toolbox/internal/SplitKindleClippings.java
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,47 @@ | ||
package net.cofcool.toolbox.internal; | ||
|
||
import java.io.File; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Arrays; | ||
import java.util.stream.Collectors; | ||
import net.cofcool.toolbox.Tool; | ||
import net.cofcool.toolbox.ToolName; | ||
import org.apache.commons.io.FileUtils; | ||
import org.apache.commons.io.FilenameUtils; | ||
|
||
public class SplitKindleClippings implements Tool { | ||
@Override | ||
public ToolName name() { | ||
return ToolName.kindle; | ||
} | ||
|
||
@Override | ||
public void run(Args args) throws Exception { | ||
var path = args.readArg("path").get().val(); | ||
var out = args.readArg("out").orElse(new Arg("", FilenameUtils.getBaseName(path) + ".md")).val(); | ||
var fileContent = FileUtils.readFileToString(new File(path), StandardCharsets.UTF_8); | ||
String strs = Arrays | ||
.stream(fileContent.split("==========")) | ||
.map(s -> { | ||
String[] split = s.split("\n"); | ||
var bookName = ""; | ||
var content = ""; | ||
if (split.length == 5) { | ||
bookName = split[0]; | ||
content = split[3]; | ||
} else { | ||
bookName = split[1]; | ||
content = split[4]; | ||
} | ||
return String.format("### %s\n\n%s\n\n", bookName, content); | ||
}) | ||
.collect(Collectors.joining()); | ||
System.out.println("Write file to " + out); | ||
FileUtils.writeStringToFile(new File(out), strs, StandardCharsets.UTF_8); | ||
} | ||
|
||
@Override | ||
public String help() { | ||
return "--path=kindle.txt --out=kindle.md"; | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
src/test/java/net/cofcool/toolbox/internal/ShellStarterTest.java
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,12 @@ | ||
package net.cofcool.toolbox.internal; | ||
|
||
import net.cofcool.toolbox.Tool.Args; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ShellStarterTest { | ||
|
||
@Test | ||
void run() throws Exception { | ||
new ShellStarter().run(new Args().arg("cmd", "git log 1.0.1..1.0.2 --oneline")); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/test/java/net/cofcool/toolbox/internal/SplitKindleClippingsTest.java
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,15 @@ | ||
package net.cofcool.toolbox.internal; | ||
|
||
import java.net.URL; | ||
import net.cofcool.toolbox.Tool; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class SplitKindleClippingsTest { | ||
|
||
@Test | ||
void run() throws Exception { | ||
URL resource = SplitKindleClippings.class.getResource("/splitKindleClippingsTest.txt"); | ||
new SplitKindleClippings().run(new Tool.Args().arg("path", resource.toString().substring(5)).arg("out", "./target/splitKindleClippingsTest.md")); | ||
} | ||
|
||
} |
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,13 @@ | ||
asda | ||
dsf | ||
sdfds | ||
dsfdsf | ||
sdfs | ||
sfsdf | ||
========== | ||
asda | ||
dsf | ||
sdfds | ||
dsfdsf | ||
sdfs | ||
========== |