Permalink
Browse files

Refactoring code to write XHTML export of Twitter statuses

  • Loading branch information...
morphex committed Apr 5, 2018
1 parent ed83036 commit 093545931bd8333f66389f98dcfc88673283b48a
Showing with 22 additions and 6 deletions.
  1. +10 −0 src/main/java/org/morphex/app/App.java
  2. +12 −6 src/main/java/org/morphex/app/WriteXHTML.java
@@ -6,6 +6,8 @@
import java.util.List;
import java.io.*;
import org.apache.commons.text.StringEscapeUtils;
/**
* Hello world!
*
@@ -15,6 +17,7 @@
public static void main( String[] args )
{
System.out.println("Starting Twitter dump");
String outputXHTML = "";
ConfigurationBuilder config = new ConfigurationBuilder();
config.setTweetModeExtended(true);
try {
@@ -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);
}
}
@@ -1,3 +1,5 @@
package org.morphex.app;
import java.io.*;
import java.nio.charset.Charset;
@@ -11,8 +13,17 @@
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") {
@@ -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.