diff --git a/src/talkCrawler.sh b/src/talkCrawler.sh index aa0bce8..e7c9293 100644 --- a/src/talkCrawler.sh +++ b/src/talkCrawler.sh @@ -3,4 +3,4 @@ CLASSPATH=.:talkCrawler.jar export CLASSPATH -java -cp $CLASSPATH talkcrawler.DailyIndex $1 +java -cp $CLASSPATH talkcrawler.TalkCrawler $1 diff --git a/src/talkcrawler/DailyIndex.java b/src/talkcrawler/DailyIndex.java index d482dc0..cfb0ae3 100644 --- a/src/talkcrawler/DailyIndex.java +++ b/src/talkcrawler/DailyIndex.java @@ -24,37 +24,6 @@ TalkCrawlerProperties prop; /** - * COMMAND - * 引数がない場合には、前日の月のクローリングを行う - * 年月が指定された場合には、指定の月のクローリングを行う - * - * @param args - * @throws IOException - * @throws java.text.ParseException - */ - public static void main(String[] args) throws IOException, ParseException { - Calendar calendar = Calendar.getInstance(); - if (args.length >= 1) { - DateFormat inputDate = new SimpleDateFormat("yyyy-MM"); - calendar.setTime(inputDate.parse(args[0])); - calendar.add(Calendar.MONTH, 1); - } - else { - calendar.setTime(new Date()); - calendar.add(Calendar.DAY_OF_MONTH, -1); - } - - DateFormat df = new SimpleDateFormat("yyyy-MMMMMMMM", Locale.UK); - df.setTimeZone(TimeZone.getTimeZone("GMT")); - String monthly = df.format(calendar.getTime()); - System.out.println("TalkCrawler "+ monthly); - - TalkCrawlerProperties prop = new TalkCrawlerProperties().load(); - DailyIndex ins = new DailyIndex(prop, monthly, "date.html"); - ins.load(); - } - - /** * * @param prop MonthlyIndex.MONTHLY_INDEX * @param dir diff --git a/src/talkcrawler/TalkCrawler.java b/src/talkcrawler/TalkCrawler.java index 6ce4d30..d8fb828 100644 --- a/src/talkcrawler/TalkCrawler.java +++ b/src/talkcrawler/TalkCrawler.java @@ -1,16 +1,57 @@ package talkcrawler; -public class TalkCrawler { +import java.io.IOException; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.Locale; +import java.util.TimeZone; - @SuppressWarnings({"UseSpecificCatch", "CallToPrintStackTrace"}) - public static void main(String[] args) { - try { - TalkCrawlerProperties prop = new TalkCrawlerProperties().load(); - MonthlyIndex ins = new MonthlyIndex(prop); - ins.load(); +public class TalkCrawler { + + /** + * COMMAND + * 引数がない場合には、前日の月のクローリングを行う + * 年月が指定された場合には、指定の月のクローリングを行う + * 引数に「all」が指定された場合には、すべてのクローリングをやり直す + * + * @param args + * @throws IOException + * @throws java.text.ParseException + */ + public static void main(String[] args) throws IOException, ParseException { + Calendar calendar = Calendar.getInstance(); + if (args.length >= 1) { + String argStr = args[0]; + if (argStr.toLowerCase().equals("all")) { + // 引数に「all」が指定された場合には、すべてのクローリングをやり直す + TalkCrawlerProperties prop = new TalkCrawlerProperties().load(); + MonthlyIndex ins = new MonthlyIndex(prop); + ins.load(); + return; + } + else { + // 年月が指定された場合には、指定の月のクローリングを行う + DateFormat inputDate = new SimpleDateFormat("yyyy-MM"); + calendar.setTime(inputDate.parse(argStr)); + calendar.add(Calendar.MONTH, 1); + } } - catch (Exception e) { - e.printStackTrace(); + else { + // 引数がない場合には、前日の月のクローリングを行う + calendar.setTime(new Date()); + calendar.add(Calendar.DAY_OF_MONTH, -1); } + + DateFormat df = new SimpleDateFormat("yyyy-MMMMMMMM", Locale.UK); + df.setTimeZone(TimeZone.getTimeZone("GMT")); + String monthly = df.format(calendar.getTime()); + System.out.println("TalkCrawler "+ monthly); + + TalkCrawlerProperties prop = new TalkCrawlerProperties().load(); + DailyIndex ins = new DailyIndex(prop, monthly, "date.html"); + ins.load(); } }