diff --git a/src/talkcrawler/Article.java b/src/talkcrawler/Article.java index e03ae67..c6e10cc 100644 --- a/src/talkcrawler/Article.java +++ b/src/talkcrawler/Article.java @@ -99,8 +99,8 @@ public void load() { boolean euc = false; try { - URL url = new URL(String.format("%s/%s/%s.html", path, dir, id)); - HttpURLConnection http = (HttpURLConnection)url.openConnection(); + URL aurl = new URL(String.format("%s/%s/%s.html", path, dir, id)); + HttpURLConnection http = (HttpURLConnection)aurl.openConnection(); http.setRequestMethod("GET"); http.connect(); try (BufferedReader rd = new BufferedReader(new InputStreamReader(http.getInputStream(), "UTF-8"))) { @@ -133,8 +133,8 @@ try { if (euc) { - URL url = new URL(String.format("%s/%s/%s.html", path, dir, id)); - HttpURLConnection http = (HttpURLConnection)url.openConnection(); + URL aurl = new URL(String.format("%s/%s/%s.html", path, dir, id)); + HttpURLConnection http = (HttpURLConnection)aurl.openConnection(); http.setRequestMethod("GET"); http.connect(); try (BufferedReader rd = new BufferedReader(new InputStreamReader(http.getInputStream(), "EUC-JP"))) { @@ -144,7 +144,6 @@ } catch (Exception ex) { Logger.getLogger(DailyIndex.class.getName()).log(Level.SEVERE, null, ex); - return; } } @@ -159,7 +158,6 @@ } if (str.startsWith("") && str.endsWith("")) { System.out.println(this.id); - String dateStr = str.substring(3, str.length() - 4); StringTokenizer st = new StringTokenizer(str, "()"); if (st.hasMoreTokens()) { @@ -171,8 +169,8 @@ } catch(ParseException e) { try { - SimpleDateFormat sdf2 = new SimpleDateFormat("''yyyy'年 'M'月 'd'日'HH:mm:ss' GMT'"); - date = sdf2.parse(date1 + date3); + SimpleDateFormat sdf3 = new SimpleDateFormat("''yyyy'年 'M'月 'd'日'HH:mm:ss' GMT'"); + date = sdf3.parse(date1 + date3); } catch (ParseException e2) { e2.printStackTrace(); @@ -190,13 +188,6 @@ } } - /* - public void post(JsonObject obj) { - JsonArray arry = Json.createArrayBuilder().add(obj).build(); - System.out.println(arry.toString()); - } - */ - void getArticle(BufferedReader reader) throws IOException { String line; boolean top = true; diff --git a/src/talkcrawler/DailyIndex.java b/src/talkcrawler/DailyIndex.java index ab722a4..06d4117 100644 --- a/src/talkcrawler/DailyIndex.java +++ b/src/talkcrawler/DailyIndex.java @@ -5,7 +5,13 @@ import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.Locale; import java.util.StringTokenizer; +import java.util.TimeZone; import java.util.logging.Level; import java.util.logging.Logger; import tool.http.Post; @@ -16,10 +22,18 @@ String file; public static void main(String[] args) throws IOException { - DailyIndex ins = new DailyIndex(MonthlyIndex.MONTHLY_INDEX, "2019-March", "date.html"); + Calendar calendar = Calendar.getInstance(); + 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()); + + DailyIndex ins = new DailyIndex(MonthlyIndex.MONTHLY_INDEX, monthly, "date.html"); ins.load(); } - + /** * * @param path @@ -78,7 +92,6 @@ } catch (Exception ex) { Logger.getLogger(DailyIndex.class.getName()).log(Level.SEVERE, null, ex); - return; } } @@ -126,14 +139,14 @@ } String getId(String str) throws IOException { - String file = ""; + String file1 = ""; StringTokenizer st = new StringTokenizer(str, ">"); if (st.hasMoreTokens()) { String no = st.nextToken().trim(); if (no.toUpperCase().startsWith(" */ @Test + @SuppressWarnings("UseSpecificCatch") public void test2014_08_008480() { try { Article ins = new Article(MonthlyIndex.MONTHLY_INDEX, "2014-August", "008480"); @@ -70,6 +74,7 @@ * https://lists.openstreetmap.org/pipermail/talk-ja/2008-March/date.html */ @Test + @SuppressWarnings("UseSpecificCatch") public void test2008_03_000000() { try { Article ins = new Article(MonthlyIndex.MONTHLY_INDEX, "2008-March", "000000");