ä»æ¥ã®æ°åãã¡ã¼ã«ã§ãç¥ãããã¦ãããå¦ç
ããã¨é«é »åº¦ã§æ¼«ç»ãè²·ã£ã¦ãããããã§ãã
çºå£²æ¥å½æ¥ã«æ¬å±ããã§è²·ããªãã¨æ°ãæ¸ã¾ãªãæ§æ ¼ãªã®ã§ãコミックダッシュ! - 漫画(マンガ)、コミックの蔵書管理と新刊発売日のチェックをサポートする総合サイト | コミックダッシュ!ã§ç®¡çãã¦ãã漫ç»ã®çºå£²æ¥ã«ã¡ã¼ã«ã§ãç¥ãããã¦ãããã³ã¼ããæ®´ãæ¸ããã¾ããã
package jp.ne.hatena.syoko_sasaki; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.regex.Pattern; import org.apache.commons.mail.EmailException; import org.apache.commons.mail.SimpleEmail; public class Comic { public static void main(String[] args) { SimpleEmail email = new SimpleEmail(); try { email.setCharset("utf-8"); email.setHostName("smtp.gmail.com"); email.setSmtpPort(587); email.setTLS(true); email.setAuthentication("gmailã¢ã«ã¦ã³ãID", "ãã¹ã¯ã¼ã"); email.addTo("ã±ã¼ã¿ã¤ã®ã¢ãã¬ã¹"); email.setFrom("gmailã¢ã«ã¦ã³ãID@gmail.com"); email.setSubject("ä»æ¥ã®æ°å"); StringBuilder comics = new StringBuilder(); for(String comic : getComics()) { comics.append(comic); comics.append("\n"); } email.setMsg(comics.toString()); email.send(); } catch (EmailException e) { e.printStackTrace(); } } private static List<String> getComics(){ List<String> comics = new ArrayList<String>(); try { URL url = new URL("http://ckworks.jp/comicdash/calendar/ã³ããã¯ããã·ã¥ã®ãã°ã¤ã³ID"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "EUC-JP")); int i = 0; int flag = 0; String line; Pattern pattern = Pattern.compile("<.+?>", Pattern.DOTALL); while ((line = reader.readLine()) != null) { line = pattern.matcher(line).replaceAll("").replaceAll(" ", ""); if(line.contains(new SimpleDateFormat("çºå£²æ¥:yyyy/MM/dd").format(new Date()))) { flag = i; } if(i == flag + 8) { comics.add(line); } i++; } reader.close(); } catch (IOException e) { throw new IllegalStateException(e.getMessage()); } return comics; } }
æ¹è¡ã³ã¼ãã®ã¨ããã¯ç°å¢ä¾åããã®ã§æ³¨æã
ãåå¼·ãããã¦ãã©ã£ãã®ã¬ã³ã¿ã«ãµã¼ãã¼ç»é²ãã¦ããããããªã
èªåã§ï¼ããcronè¨å®ãããã
ãã¨ãæ°è¦æ¼«ç»éæã®ããã«ããã®é±ã«çºå£²ããããã¹ã¦ã®æ¼«ç»ãæææ¥ã®æãç¥ãããã¦ãããä½ãã«å¤ããããã¨ãæã£ããã
ããã ã¨å¤ããããããããã¼ãã