diff --git a/demo.iml b/demo.iml index b88d9d8..caafeac 100644 --- a/demo.iml +++ b/demo.iml @@ -41,6 +41,8 @@ + + @@ -177,6 +179,5 @@ - \ No newline at end of file diff --git a/docker/pg/1-createTable.sql b/docker/pg/1-createTable.sql index 6f057a2..7af9cec 100644 --- a/docker/pg/1-createTable.sql +++ b/docker/pg/1-createTable.sql @@ -55,6 +55,16 @@ insert into users(name, mail, filterlevel) values ('pinapple.chocomint', 'hogehogehoge@hoge.com', 3) ; -insert into emolog(userid, friendid, name, latestemolog) -values (1, 2, 'hoge', 'emojihoge') +insert into friend(userid, friendid, name, latestemolog) values + (1, 2, 'hoge', 'emojihoge'), + (2, 1, 'Trump', ':smile:'), + (1, 3, 'kim jyoung-un', ':sad:') ; + +insert into emolog(userid, friendid, create_at, contents) values + (1, 2, current_timestamp, ':mountain:'), + (2, 1, current_timestamp, ':hotel:'), + (1, 3, current_timestamp, ':gorilla:'), + (3, 1, current_timestamp, ':space:') +; + diff --git a/src/main/java/com/example/demo/controller/HtmlController.java b/src/main/java/com/example/demo/controller/HtmlController.java new file mode 100644 index 0000000..66994ac --- /dev/null +++ b/src/main/java/com/example/demo/controller/HtmlController.java @@ -0,0 +1,74 @@ +package com.example.demo.controller; + +import com.vdurmont.emoji.EmojiManager; +import org.springframework.ui.ModelMap; +import com.vdurmont.emoji.EmojiParser; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import twitter4j.TwitterException; + +import java.util.ArrayList; +import java.util.List; + + +@Controller +@RequestMapping(path = "/") +public class HtmlController { + @RequestMapping(path = "/", method = RequestMethod.GET) + public String index() { + return "index"; + } + + @RequestMapping(path = "/enter", method = RequestMethod.GET) + public String crawling( + ModelMap modelMap + ) throws Exception { + + List keyword_tweets = new ArrayList(); + List keyword_images = new ArrayList(); + + keyword_tweets = ViewController.get_NLU_keywords("CNN", 100000); + keyword_images = ViewController.get_image_keywords("CNN", 100000); + + List emojiList = new ArrayList(); + + // TODO: ここでDBアクセスかなんかlook upする??。->つかささんのやつくっつける。 + + // 文字列整形の方(テキトーに::をつける方) + for( String keyword : keyword_tweets){ + try{ + String tmp = EmojiParser.parseToHtmlDecimal(":" + keyword + ":"); + emojiList.add(tmp); + } + catch (NullPointerException ignored){} + } + + for( String keyword : keyword_images){ + try{ + String tmp = EmojiParser.parseToHtmlDecimal(":" + keyword + ":"); + emojiList.add(tmp); + } + catch (NullPointerException ignored){} + } + + // で、:hoge:みたいなんが得られたらEmologにパースして、それをaddAttributeする.->データがdbに入っていないとThymeleaf側で取り出せん模様。 +// modelMap.addAttribute("emologs", emojiList); + + + // emojiList : ["😃", "😃", "😃"] みたいな感じ。 + // emojiListから一つの文字列に直す。 + String emolog = String.join("", emojiList); + + + //TODO: ここで得られたemologをdbに登録する処理… + // emolog(userid, friendid, create_at, contents) + // userid = 1, friendid = 2, create_at = TIMESTAMP??, contents = emolog + + + + + + return "friendlist"; + } +} diff --git a/src/main/java/com/example/demo/controller/ViewController.java b/src/main/java/com/example/demo/controller/ViewController.java index 0db0510..c629ada 100644 --- a/src/main/java/com/example/demo/controller/ViewController.java +++ b/src/main/java/com/example/demo/controller/ViewController.java @@ -28,6 +28,7 @@ public class ViewController { @Autowired JdbcTemplate jdbcTemplate; + @RequestMapping(path = "/users", method = RequestMethod.GET) public String index() { List> list; @@ -94,7 +95,7 @@ public List collect_image_keywords_from_tweets( // コントローラは関数として呼び出すのはキツイっぽいのでとりま関数として取り出してる。。 //TODO: TwitterControllerやNLUControllerから共通部分を分離して別クラスとして保持。 - private QueryResult search_user(String username, long tweet_id) throws TwitterException { + private static QueryResult search_user(String username, long tweet_id) throws TwitterException { // 初期化 Twitter twitter = new TwitterFactory().getInstance(); Query query = new Query(); @@ -106,7 +107,7 @@ private QueryResult search_user(String username, long tweet_id) throws TwitterEx return twitter.search(query); } - private String NLU(String text) { + private static String NLU(String text) { IamAuthenticator authenticator = new IamAuthenticator("fVfaYMA7tCh4zInWBhTBb5t69xQryK7ObKl42nampynG"); NaturalLanguageUnderstanding naturalLanguageUnderstanding = new NaturalLanguageUnderstanding("2019-07-12", authenticator); naturalLanguageUnderstanding.setServiceUrl("https://api.jp-tok.natural-language-understanding.watson.cloud.ibm.com/instances/ac3df365-93f6-4255-beb8-620d66041251"); @@ -140,7 +141,7 @@ private String NLU(String text) { } - private String ImageProcessing(String url) throws FileNotFoundException { + private static String ImageProcessing(String url) throws FileNotFoundException { IamAuthenticator authenticator = new IamAuthenticator("8nwN0eKp7eZ73So4DLdPndp_yv-vtlI27pN1wK2TjVg1"); VisualRecognition visualRecognition = new VisualRecognition("2019-07-12", authenticator); @@ -161,4 +162,43 @@ private String ImageProcessing(String url) throws FileNotFoundException { } + //関数もおいちゃえ + public static List get_NLU_keywords(String username, long tweet_id) throws TwitterException { + QueryResult result = search_user(username, tweet_id); + ArrayList NLU_results = new ArrayList<>(); + + for (Status status : result.getTweets()) { + String tmp = NLU(status.getText()); + if(tmp != null) { +// System.out.println(tmp); + NLU_results.add(tmp); + } + } + + return NLU_results; + //TODO: 整形する必要あるかも? + } + + + public static List get_image_keywords(String username, long tweet_id) throws Exception { + QueryResult result = search_user(username, tweet_id); + ArrayList imageprocessing_results = new ArrayList<>(); + + for (Status status : result.getTweets()) { + if(status.getMediaEntities().length > 0) { +// System.out.println(status.getMediaEntities()[0].getMediaURL()); + + String tmp = ImageProcessing(status.getMediaEntities()[0].getMediaURL()); + if (tmp != null) { +// System.out.println(tmp); + imageprocessing_results.add(tmp); + } + } + } + + return imageprocessing_results; +// ["call center", "people", "newsreader"]みたいなんがくる。 + + } + } \ No newline at end of file diff --git a/src/main/resources/static/css/style.css b/src/main/resources/static/css/style.css index 0272a3f..427a9ad 100644 --- a/src/main/resources/static/css/style.css +++ b/src/main/resources/static/css/style.css @@ -71,6 +71,39 @@ a:hover { height: 100%; background-color: #fffacd; } + +.global-nav { + height: 10%; + width: 100%; + + width: 960px; + margin: 0 auto; + position: fixed; + bottom: 0; +} + +.global-nav li{ + background-color: #f0f8ff; + width: 33%; + float: left; + margin: 5px 1px; + text-align: center; + font-size: 20px; + list-style: none; + font-family: 'Bitter',serif; +} + +.global-nav li a{ + padding: 5px 5%; +} + + +.global-nav li a:hover{ + border-bottom: 2px solid; + padding-bottom: 3px; + text-decoration: none; +} + /* chat.html 部分*/ .friend-name { @@ -81,11 +114,11 @@ ul.header_ul{ width: 100%; } ul.header_ul li{ - display: inline-block; - vertical-align:middle; - margin: 0; - padding: 0; - width: 45%; + display: inline-block; + vertical-align:middle; + margin: 0; + padding: 0; + width: 45%; } .emolog { @@ -109,16 +142,16 @@ ul.header_ul li{ } .emolog_ul { - width: 100%; + width: 100%; } .emolog_ul li { - text-align: center; - display: inline-block; - vertical-align:middle; - margin: 0; - padding: 0; + text-align: center; + display: inline-block; + vertical-align:middle; + margin: 0; + padding: 0; } .emolog_ul li.emolog-date-cover { vertical-align:top; @@ -144,3 +177,24 @@ ul.header_ul li{ font-size: 20px; font-family: 'Bitter',serif; } + +/* emologlist.html*/ +.emolog-list { + height: 90%; + background-color: #f5f5f5; + overflow: auto; +} +.emolog-list li { + border-bottom: solid 1px #000000; + list-style: none; + text-align: center; +} +.emolog-date { + float: left; + text-align: left; + margin: 5px 5px 0 0; + font-size: 18px; + font-family: 'Bitter',serif; +} + +/* emologlist.html 終わり*/ diff --git a/src/main/resources/templates/chat.html b/src/main/resources/templates/chat.html index d2c89a0..39ac675 100644 --- a/src/main/resources/templates/chat.html +++ b/src/main/resources/templates/chat.html @@ -12,7 +12,7 @@
  • - backbutton + backbutton
  • diff --git a/src/main/resources/templates/emologlist.html b/src/main/resources/templates/emologlist.html index 3d43151..b530c50 100644 --- a/src/main/resources/templates/emologlist.html +++ b/src/main/resources/templates/emologlist.html @@ -22,33 +22,18 @@
    - +
    +
diff --git a/src/main/resources/templates/friendlist.html b/src/main/resources/templates/friendlist.html new file mode 100644 index 0000000..fe14abf --- /dev/null +++ b/src/main/resources/templates/friendlist.html @@ -0,0 +1,58 @@ + + + + + Friendlist + + +
+
+ +
+ + +
    +
  • + +

    unkokun

    + + +

    + emolog_arrow + +
  • +
  • +

    8月17日

    + +

    🍉🍉🍉🍉🍉🍉🍉

    + emolog_arrow +
  • +
  • +

    8月16日

    + +

    🍉🍉🍉🍉🍉🍉🍉

    + emolog_arrow +
  • +
  • +

    8月15日

    + +

    🍉🍉🍉🍉🍉🍉🍉

    + emolog_arrow +
  • +
+
+ + + +
+
+ + + + \ No newline at end of file diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html new file mode 100644 index 0000000..183fa7c --- /dev/null +++ b/src/main/resources/templates/index.html @@ -0,0 +1,10 @@ + + + + + index + + +ENTER!! + + \ No newline at end of file diff --git a/target/classes/com/example/demo/controller/ViewController.class b/target/classes/com/example/demo/controller/ViewController.class index 93d81be..8a9be35 100644 Binary files a/target/classes/com/example/demo/controller/ViewController.class and b/target/classes/com/example/demo/controller/ViewController.class differ