diff options
author | Peter Wu <peter@lekensteyn.nl> | 2014-05-09 14:44:53 +0200 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2014-05-09 14:44:53 +0200 |
commit | 71a405ee7b73f91298b029f4d817cc13731340cc (patch) | |
tree | d5b6c5d6d9d3c146788348ebe402c3ef2ca99f1b | |
parent | 36152ad981e3c6cd37c3771e3d4a393535400f91 (diff) | |
download | Datafiller-71a405ee7b73f91298b029f4d817cc13731340cc.tar.gz |
Add "--skipdb" option to allow printing results
For testing whether the data is correct or not.
-rw-r--r-- | src/main/Main.java | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/main/Main.java b/src/main/Main.java index b21ea16..999b307 100644 --- a/src/main/Main.java +++ b/src/main/Main.java @@ -36,6 +36,10 @@ public class Main { private String m_filename; private final ConnectionBuilder cb; + /** + * Whether the database should be contacted or not. + */ + private boolean skipDb; public Main(String[] args) { // default connection properties @@ -44,11 +48,19 @@ public class Main { .setUsername("postgres") .setPassword("2IOC02") .setDbName("Twitter"); + skipDb = false; /* parse the global options. */ parseGlobalOptions(args); } + private void printTweets(ITweetReader reader) throws IOException { + Tweet tweet; + while ((tweet = reader.getTweet()) != null) { + System.out.println(tweet); + } + } + private void tweetsToDb(ITweetReader reader) throws IOException { Tweet tweet; try (Connection connection = cb.create()) { @@ -71,7 +83,11 @@ public class Main { } else { reader = new FileTweetReader(m_filename); } - tweetsToDb(reader); + if (skipDb) { + printTweets(reader); + } else { + tweetsToDb(reader); + } } catch (JsonSyntaxException ex) { System.err.println("Got an invalid tweet: " + ex); } catch (IOException ex) { @@ -98,6 +114,8 @@ public class Main { cb.setPassword(getArg(args, ++i, "--dbpass")); } else if ("--dbname".equals(args[i])) { cb.setDbName(getArg(args, ++i, "--dbname")); + } else if ("--skipdb".equals(args[i])) { + skipDb = true; } else if (args[i].startsWith("-")) { throw new IllegalArgumentException("Invalid option: " + args[i]); } else { @@ -136,6 +154,7 @@ public class Main { " --dbuser USER Database username (defaults to 'postgres')", " --dbpass PASS Database password (defaults to '2IOC02')", " --dbname NAME Database name (defaults to 'Twitter')", + " --skipdb Do not contact the database at all, just print data.", "", "If no tweets file is given, data will be read from standard input." }; |