OSDN Git Service

feat: add easter
authorhizumiaoba <56146205+hizumiaoba@users.noreply.github.com>
Tue, 28 Dec 2021 10:42:09 +0000 (19:42 +0900)
committerhizumiaoba <56146205+hizumiaoba@users.noreply.github.com>
Tue, 28 Dec 2021 10:42:09 +0000 (19:42 +0900)
BREAKING CHANGE: The title is now active because of this update.

generated/database.json
generated/easter.json [new file with mode: 0644]
src/com/ranfa/lib/Easter.java [new file with mode: 0644]
src/com/ranfa/main/DelesteRandomSelector.java
src/test/EasterTest.java [new file with mode: 0644]

index 2df4091..7d54c8a 100644 (file)
     "level" : 30,
     "notes" : 999,
     "albumType" : "Not-implemented"
+  }, {
+    "attribute" : "パッション",
+    "name" : "冬空プレシャス",
+    "difficulty" : "LIGHT",
+    "level" : 8,
+    "notes" : 145,
+    "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "パッション",
+    "name" : "冬空プレシャス",
+    "difficulty" : "TRICK",
+    "level" : 16,
+    "notes" : 367,
+    "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "全タイプ",
+    "name" : "Happy New Yeah!",
+    "difficulty" : "LIGHT",
+    "level" : 7,
+    "notes" : 166,
+    "albumType" : "Not-Implemented"
+  }, {
+    "attribute" : "全タイプ",
+    "name" : "Happy New Yeah!",
+    "difficulty" : "TRICK",
+    "level" : 16,
+    "notes" : 405,
+    "albumType" : "Not-Implemented"
   } ]
 }
\ No newline at end of file
diff --git a/generated/easter.json b/generated/easter.json
new file mode 100644 (file)
index 0000000..855dbe1
--- /dev/null
@@ -0,0 +1,216 @@
+{
+  "川島瑞樹" : "11月25日",
+  "砂塚あきら" : "10月7日",
+  "島村卯月" : "4月24日",
+  "佐々木千枝" : "6月7日",
+  "小室千奈美" : "6月9日",
+  "ジュリア" : "9月26日",
+  "衛藤美紗希" : "3月18日",
+  "榊原里美" : "8月27日",
+  "鷹富士茄子" : "1月1日",
+  "的場梨沙" : "11月19日",
+  "宮本フレデリカ" : "2月14日",
+  "梅木音葉" : "6月20日",
+  "涼宮星花" : "8月28日",
+  "日野茜" : "8月4日",
+  "若林智香" : "8月30日",
+  "上条春菜" : "4月10日",
+  "天海春香" : "4月3日",
+  "小日向美穂" : "12月16日",
+  "前川みく" : "2月22日",
+  "西園寺琴歌" : "1月23日",
+  "乙倉悠貴" : "10月6日",
+  "矢口美羽" : "7月10日",
+  "関裕美" : "8月17日",
+  "堀裕子" : "3月13日",
+  "城ヶ崎莉嘉" : "7月30日",
+  "西島櫂" : "8月17日",
+  "クラリス" : "8月26日",
+  "水本ゆかり" : "10月18日",
+  "久川颯" : "6月16日",
+  "福山舞" : "1月21日",
+  "綾瀬穂乃香" : "5月29日",
+  "藤居朋" : "7月1日",
+  "斉藤洋子" : "12月29日",
+  "ヘレン" : "4月4日",
+  "月宮雅" : "10月30日",
+  "白坂小梅" : "3月28日",
+  "ケイト" : "8月15日",
+  "結城晴" : "7月17日",
+  "ベテラントレーナー" : "9月10日",
+  "小関麗奈" : "3月5日",
+  "渋谷凛" : "8月10日",
+  "瀬名詩織" : "1月10日",
+  "秋月律子" : "6月23日",
+  "仙崎恵磨" : "6月27日",
+  "橘ありす" : "7月31日",
+  "古賀小春" : "4月1日",
+  "三好紗南" : "6月25日",
+  "真鍋いつき" : "12月29日",
+  "道明寺歌鈴" : "1月1日",
+  "夢見りあむ" : "9月12日",
+  "桐生つかさ" : "2月24日",
+  "村松さくら" : "3月27日",
+  "日高愛" : "6月25日",
+  "上田鈴帆" : "10月26日",
+  "工藤忍" : "3月9日",
+  "大和亜季" : "12月16日",
+  "篠原礼" : "11月22日",
+  "岸部彩華" : "11月13日",
+  "伊集院惠" : "9月24日",
+  "楊菲菲" : "9月29日",
+  "木場真奈美" : "8月8日",
+  "二宮飛鳥" : "2月3日",
+  "佐藤心" : "7月22日",
+  "新田美波" : "7月27日",
+  "持田亜里沙" : "8月24日",
+  "小松伊吹" : "11月17日",
+  "大槻唯" : "5月7日",
+  "吉岡沙紀" : "5月8日",
+  "水木聖來" : "4月27日",
+  "神谷奈緒" : "9月16日",
+  "神崎蘭子" : "4月8日",
+  "十時愛梨" : "12月8日",
+  "五十嵐響子" : "8月10日",
+  "水野翠" : "12月5日",
+  "遊佐こずえ" : "2月19日",
+  "池袋晶葉" : "6月10日",
+  "浅利七海" : "10月9日",
+  "桃井あずき" : "7月7日",
+  "原田美世" : "11月14日",
+  "江上椿" : "2月6日",
+  "藤本里奈" : "10月14日",
+  "星井美希" : "11月23日",
+  "高垣楓" : "6月14日",
+  "市原仁奈" : "2月8日",
+  "土屋亜子" : "5月2日",
+  "及川雫" : "6月3日",
+  "棟方愛海" : "8月1日",
+  "菊地真" : "8月29日",
+  "龍崎薫" : "7月20日",
+  "ルーキートレーナー" : "3月10日",
+  "八神マキノ" : "11月7日",
+  "南条光" : "9月13日",
+  "松本沙理奈" : "9月1日",
+  "城ヶ崎美嘉" : "11月12日",
+  "和久井留美" : "4月7日",
+  "多田李衣菜" : "6月30日",
+  "黒川千秋" : "2月26日",
+  "杉坂海" : "7月20日",
+  "佐久間まゆ" : "9月7日",
+  "小早川紗枝" : "10月18日",
+  "難波笑美" : "5月1日",
+  "柳瀬美由紀" : "3月16日",
+  "柊志乃" : "12月25日",
+  "中野有香" : "3月23日",
+  "古澤頼子" : "5月18日",
+  "松永涼" : "10月1日",
+  "椎名法子" : "10月10日",
+  "マスタートレーナー" : "12月10日",
+  "三村かな子" : "1月6日",
+  "トレーナー" : "6月10日",
+  "愛野渚" : "8月1日",
+  "白雪千夜" : "2月4日",
+  "一ノ瀬志希" : "5月30日",
+  "安斎都" : "1月6日",
+  "氏家むつみ" : "7月13日",
+  "岡崎泰葉" : "7月16日",
+  "松尾千鶴" : "3月21日",
+  "大西由里子" : "3月20日",
+  "高峯のあ" : "3月25日",
+  "姫川友紀" : "9月14日",
+  "槙原志保" : "4月27日",
+  "片桐早苗" : "3月7日",
+  "四条貴音" : "1月21日",
+  "大沼くるみ" : "3月30日",
+  "財前時子" : "4月18日",
+  "浜口あやめ" : "1月13日",
+  "浅野風香" : "2月11日",
+  "森久保乃々" : "8月27日",
+  "望月聖" : "12月25日",
+  "相葉夕美" : "4月15日",
+  "長富蓮実" : "3月19日",
+  "東郷あい" : "2月7日",
+  "高森藍子" : "7月25日",
+  "桜井夢子" : "10月24日",
+  "高橋礼子" : "5月8日",
+  "間中美里" : "11月6日",
+  "我那覇響" : "10月10日",
+  "櫻井桃華" : "4月8日",
+  "松原早耶" : "12月28日",
+  "辻野あかり" : "11月5日",
+  "双海亜美" : "5月22日",
+  "本田未央" : "12月1日",
+  "喜多見柚" : "12月2日",
+  "兵藤レナ" : "10月3日",
+  "脇山珠美" : "9月20日",
+  "秋月涼" : "9月15日",
+  "松山久美子" : "1月21日",
+  "如月千早" : "2月25日",
+  "ナターリア" : "6月29日",
+  "相馬夏美" : "7月23日",
+  "首藤葵" : "8月18日",
+  "双海真美" : "5月22日",
+  "三浦あずさ" : "7月19日",
+  "沢田麻理菜" : "5月6日",
+  "木村夏樹" : "8月19日",
+  "野々村そら" : "1月3日",
+  "久川凪" : "6月16日",
+  "サイネリア" : "12月14日",
+  "佐城雪美" : "9月28日",
+  "浜川愛結奈" : "5月25日",
+  "奥山沙織" : "6月12日",
+  "赤城みりあ" : "4月14日",
+  "イヴ・サンタクロース" : "12月24日",
+  "塩見周子" : "12月12日",
+  "西川保奈美" : "10月23日",
+  "依田芳乃" : "7月3日",
+  "大原みちる" : "4月12日",
+  "黒埼ちとせ" : "11月10日",
+  "星輝子" : "6月6日",
+  "安部菜々" : "5月15日",
+  "喜多日菜子" : "4月6日",
+  "有浦柑奈" : "3月6日",
+  "柳清良" : "5月12日",
+  "北条加蓮" : "9月5日",
+  "藤原肇" : "6月15日",
+  "鷺沢文香" : "10月27日",
+  "相川千夏" : "11月11日",
+  "萩原雪歩" : "12月24日",
+  "村上巴" : "1月3日",
+  "早坂美玲" : "5月9日",
+  "双葉杏" : "9月2日",
+  "水谷絵理" : "3月7日",
+  "緒方智絵里" : "6月11日",
+  "服部瞳子" : "10月11日",
+  "キャシー・グラハム" : "9月19日",
+  "大石泉" : "11月11日",
+  "井村雪菜" : "8月27日",
+  "向井拓海" : "8月7日",
+  "栗原ネネ" : "9月9日",
+  "北川真尋" : "2月17日",
+  "荒木比奈" : "4月9日",
+  "高槻やよい" : "3月25日",
+  "速水奏" : "7月1日",
+  "赤西瑛梨華" : "7月7日",
+  "成宮由愛" : "11月3日",
+  "輿水幸子" : "11月25日",
+  "アナスタシア" : "9月19日",
+  "海老原菜帆" : "8月3日",
+  "水瀬伊織" : "5月5日",
+  "三船美優" : "2月25日",
+  "諸星きらり" : "9月1日",
+  "最上静香" : "9月14日",
+  "相原雪乃" : "2月14日",
+  "白菊ほたる" : "4月19日",
+  "ライラ" : "5月21日",
+  "冴島清美" : "9月26日",
+  "並木芽衣子" : "10月14日",
+  "丹羽仁美" : "6月4日",
+  "日下部若葉" : "5月4日",
+  "桐野アヤ" : "4月8日",
+  "横山千佳" : "12月18日",
+  "今井加奈" : "3月3日",
+  "太田優" : "1月28日",
+  "メアリー・コクラン" : "1月19日"
+}
\ No newline at end of file
diff --git a/src/com/ranfa/lib/Easter.java b/src/com/ranfa/lib/Easter.java
new file mode 100644 (file)
index 0000000..dcdcb47
--- /dev/null
@@ -0,0 +1,99 @@
+package com.ranfa.lib;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.select.Elements;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectWriter;
+
+public class Easter {
+
+       private final Date TODAY;
+       private final String dATE_FORMAT_STRING = "M月d日";
+       private final String BIRTH_DATA_URL = "generated/easter.json";
+       private final String WEBURL = "https://imas.gamedbs.jp/cg/idol/birthday";
+
+       private Logger logger = LoggerFactory.getLogger(Easter.class);
+       private Map<String, String> BirthData = this.fetchBirthData();
+
+       public Easter() {
+               if(Files.notExists(Paths.get(this.BIRTH_DATA_URL))) {
+                       this.writeBirthData(this.BirthData);
+               }
+               this.logger.info("LeT's mAkE ThIs aPp FuNnY...");
+               this.TODAY = new Date();
+       }
+
+       public Map<String, String> readBirthData() {
+               Map<String, String> res = null;
+               try {
+                       res = new ObjectMapper().readValue(Paths.get(this.BIRTH_DATA_URL).toFile(), new TypeReference<Map<String, String>>() {});
+               } catch (IOException e) {
+                       this.logger.warn("Error while reading database from local.", e);
+               }
+               return res;
+       }
+
+       public void writeBirthData(Map<String, String> data) {
+               ObjectWriter writer = new ObjectMapper().writer(new DefaultPrettyPrinter());
+               try {
+                       writer.writeValue(Paths.get(this.BIRTH_DATA_URL).toFile(), data);
+               } catch (IOException e) {
+                       this.logger.error("Error while writing to database for easter.", e);
+               }
+       }
+
+       public Map<String, String> fetchBirthData() {
+               Map<String, String> res = new HashMap<>();
+               try {
+                       Document document = Jsoup.connect(this.WEBURL)
+                                       .userAgent("java/DelesteRandomSelector More information is available at https;//github.com/hizumiaoba/DelesteRandomSelector/")
+                                       .maxBodySize(0)
+                                       .timeout(0)
+                                       .get();
+                       Elements elements = document.getElementsByClass("font0");
+                       elements.stream()
+                       .forEachOrdered(element -> {
+                               String[] data = element.text().split(" ");
+                               res.put(data[1], data[0]);
+                       });
+                       if(elements.size() != res.size()) {
+                               throw new IllegalArgumentException(new IOException());
+                       }
+               } catch (IOException e) {
+                       this.logger.error("Error while fetching data for easter. this is not good...", e);
+               }
+               return res;
+       }
+
+       public String getTodaysBirth() {
+               Map<String, String> birthData = this.readBirthData();
+               SimpleDateFormat format = new SimpleDateFormat(this.dATE_FORMAT_STRING);
+               String todayDateString = format.format(this.TODAY);
+               List<String> res =  birthData.entrySet().stream()
+                               .filter((e) -> e.getValue().equals(todayDateString))
+                               .map(e -> e.getKey())
+                               .collect(Collectors.toList());
+               StringBuilder builder = new StringBuilder("Happy Birth Day! : ");
+               for(String element : res) {
+                       builder.append(element);
+               }
+               return res.isEmpty() ? "" : builder.toString();
+       }
+
+}
index 0c12a1c..613190c 100644 (file)
@@ -33,6 +33,7 @@ import com.jgoodies.forms.layout.FormLayout;
 import com.jgoodies.forms.layout.FormSpecs;
 import com.jgoodies.forms.layout.RowSpec;
 import com.ranfa.lib.CheckVersion;
+import com.ranfa.lib.Easter;
 import com.ranfa.lib.EstimateAlbumTypeCycle;
 import com.ranfa.lib.ManualUpdateThreadImpl;
 import com.ranfa.lib.Scraping;
@@ -78,6 +79,7 @@ public class DelesteRandomSelector extends JFrame {
        private ManualUpdateThreadImpl impl;
        private Thread manualUpdateThread;
        private JButton btnManualUpdate;
+       private Easter easter;
 
        /**
         * Launch the application.
@@ -165,6 +167,8 @@ public class DelesteRandomSelector extends JFrame {
                        CompletableFuture<Void> updatedFuture = getWholeDataFuture.thenAcceptBothAsync(getFromJsonFuture, updateConsumer, es);
                        updatedFuture.thenRunAsync(setEnabled, es);
                }
+               this.easter = new Easter();
+               this.setTitle(this.easter.getTodaysBirth());
                this.logger.debug("Version: {}", CheckVersion.getVersion());
                this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                // this.setBounds(100, 100, this.property.getWindowWidth(), this.property.getWindowHeight());
diff --git a/src/test/EasterTest.java b/src/test/EasterTest.java
new file mode 100644 (file)
index 0000000..9c03bfd
--- /dev/null
@@ -0,0 +1,24 @@
+package test;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+
+import com.ranfa.lib.Easter;
+
+public class EasterTest {
+
+       private Easter easter = new Easter();
+
+       // nonNull tests
+       @Test
+       public void nonNullWebData() {
+               assertNotNull(this.easter.fetchBirthData());
+       }
+
+       @Test
+       public void nonNullLocalData() {
+               assertNotNull(this.easter.readBirthData());
+       }
+
+}