Skip to content

Commit

Permalink
Refactoring code to write XHTML export of Twitter statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
morphex committed Apr 5, 2018
1 parent ed83036 commit 0935459
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/main/java/org/morphex/app/App.java
Expand Up @@ -6,6 +6,8 @@
import java.util.List;
import java.io.*;

import org.apache.commons.text.StringEscapeUtils;

/**
* Hello world!
*
Expand All @@ -15,6 +17,7 @@ public class App
public static void main( String[] args )
{
System.out.println("Starting Twitter dump");
String outputXHTML = "";
ConfigurationBuilder config = new ConfigurationBuilder();
config.setTweetModeExtended(true);
try {
Expand All @@ -25,13 +28,20 @@ public static void main( String[] args )
for (Status status : twitter.getUserTimeline()) {
System.out.println(status.getText());
System.out.println("----------------------");
outputXHTML = outputXHTML + "<div class='tweet'>" +
StringEscapeUtils.escapeXml10(status.getText()) +
"</div>";
}
WriteXHTML.writeFile(outputXHTML);
} catch (TwitterException exception) {
exception.printStackTrace();
System.exit(-1);
} catch (IOException exception) {
exception.printStackTrace();
System.exit(-1);
} catch (Exception exception) {
exception.printStackTrace();
System.exit(-1);
}
}

Expand Down
18 changes: 12 additions & 6 deletions src/main/java/org/morphex/app/WriteXHTML.java
@@ -1,3 +1,5 @@
package org.morphex.app;

import java.io.*;
import java.nio.charset.Charset;

Expand All @@ -11,8 +13,17 @@ public static byte[] e(String toEncode) throws Exception {
return toEncode.getBytes(charset_);
}

public static void main(String[] args) throws Exception {
public static void writeFile(String html) throws Exception {
FileOutputStream out = new FileOutputStream("test.html");
out.write(e(header));
out.write(e(html));
out.write(e(footer));
out.close();
}

public static void main(String[] args) throws Exception {
writeFile(("This is a test"));

/*
// Disabled because W3C validator won't validate with BOM
if (charset_ == "UTF-16LE") {
Expand All @@ -31,10 +42,5 @@ public static void main(String[] args) throws Exception {
throw new java.lang.Error("Unsupported encoding for unicode BOM");
}
*/
out.write(e(header));
String test = new String("This is a test");
out.write(e("This is a test"));
out.write(e(footer));
out.close();
}
}

0 comments on commit 0935459

Please sign in to comment.