diff --git a/demo.iml b/demo.iml new file mode 100644 index 0000000..b5292df --- /dev/null +++ b/demo.iml @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 7b731cf..0b5a1a8 100644 --- a/pom.xml +++ b/pom.xml @@ -18,6 +18,20 @@ 11 + + + twitter4j.org + twitter4j.org Repository + http://twitter4j.org/maven2 + + true + + + true + + + + org.springframework.boot @@ -58,6 +72,11 @@ + + org.twitter4j + twitter4j-core + [4.0,) + @@ -65,6 +84,11 @@ org.springframework.boot spring-boot-maven-plugin + + + src/main/resources/twitter4j.properties + + diff --git a/src/main/java/com/example/demo/DemoApplication.java b/src/main/java/com/example/demo/DemoApplication.java index 452d348..7969051 100644 --- a/src/main/java/com/example/demo/DemoApplication.java +++ b/src/main/java/com/example/demo/DemoApplication.java @@ -9,20 +9,20 @@ @SpringBootApplication public class DemoApplication implements CommandLineRunner { - public static void main(String[] args) { - SpringApplication.run(DemoApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(DemoApplication.class, args); + } +q + @Autowired + JdbcTemplate jdbcTemplate; - @Autowired - JdbcTemplate jdbcTemplate; - - @Override // アプリ起動時に実行される。 - public void run(String... strings) throws Exception { - jdbcTemplate.execute("CREATE TABLE customers(" + - "id SERIAL, first_name VARCHAR(255), last_name VARCHAR(255))"); - - jdbcTemplate.update("INSERT INTO customers(first_name, last_name) VALUES ('John','Woo')"); - } + @Override // アプリ起動時に実行される。 + public void run(String... strings) throws Exception { +// jdbcTemplate.execute("CREATE TABLE customers(" + +// "id SERIAL, first_name VARCHAR(255), last_name VARCHAR(255))"); +// +// jdbcTemplate.update("INSERT INTO customers(first_name, last_name) VALUES ('John','Woo')"); + } -} +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/controller/ViewController.java b/src/main/java/com/example/demo/controller/ViewController.java index 902156b..8e5b2e2 100644 --- a/src/main/java/com/example/demo/controller/ViewController.java +++ b/src/main/java/com/example/demo/controller/ViewController.java @@ -7,10 +7,9 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; +import twitter4j.*; @RestController @RequestMapping(path = "/") @@ -28,9 +27,49 @@ public String index() { } @RequestMapping(path = "/users/{id}", method = RequestMethod.GET) - public String read(@PathVariable String id) { + public String read(@PathVariable("id") String id) { List> list; list = jdbcTemplate.queryForList("select * from users where id = ?", id); return list.toString(); } + + @RequestMapping(path = "/search_keyword", method = RequestMethod.GET) + public String search_keyowrd(@RequestParam(name = "searchword", defaultValue = "チンチン") String searchword) throws TwitterException { + // 初期化 + Twitter twitter = new TwitterFactory().getInstance(); + Query query = new Query(searchword); + + QueryResult result = twitter.search(query); + + // for debug. show tweet results on CLI + for (Status status : result.getTweets()) { + System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText()); + } + + return "a"; + } + + @RequestMapping(path = "/search_user", method = RequestMethod.GET) + public String search_user(@RequestParam(name = "username", defaultValue = "CNN") String username, + @RequestParam(name = "tweet_id", defaultValue = "1000000") long tweet_id + ) throws TwitterException { + // 初期化 + Twitter twitter = new TwitterFactory().getInstance(); + Query query = new Query(); + + //ユーザーネームで指定.sinceId以降のtweetから15個取ってくる.最新のツイートから時系列順に取ってくるっぽい。 + query.setQuery("from:" + username); + query.setSinceId(tweet_id); + + QueryResult result = twitter.search(query); + + //for debug on CLI. + for (Status status : result.getTweets()) { + System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText()); + } + + //TODO: ここで取ってきたLatestTweetIdを保存しておいて、次回からそのidのツイート以降のツイートを拾ってくればOK + + return "a"; + } } \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 56b652b..33a0b89 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -10,4 +10,6 @@ spring.h2.console.settings.web-allow-others=true spring.datasource.driver-class-name=org.postgresql.Driver spring.datasource.url=jdbc:postgresql://localhost:5432/test_db spring.datasource.username=postgres -spring.datasource.password=postgres \ No newline at end of file +spring.datasource.password=postgres + +jsonStoreEnabled=true \ No newline at end of file diff --git a/src/main/resources/twitter4j.properties b/src/main/resources/twitter4j.properties new file mode 100644 index 0000000..3f06541 --- /dev/null +++ b/src/main/resources/twitter4j.properties @@ -0,0 +1,5 @@ +debug=true +oauth.consumerKey= 53i2wkDRrQjw4zUkHdTpgxxTx +oauth.consumerSecret= dpgXNsrU8Tk2JZYG9tt6cVpHvcsGb7lq1RwxK2Ibe45aMV6eTT +oauth.accessToken= 211508041-Ut8dYloaixL0BKyJTvqluKak5VHFwMILZo3eyLDJ +oauth.accessTokenSecret= NkfQIRnHHaYMqJwrcVtjcshq7DKcdFVJteQkp4fXST6vl \ No newline at end of file diff --git a/target/classes/META-INF/demo.kotlin_module b/target/classes/META-INF/demo.kotlin_module new file mode 100644 index 0000000..a49347a Binary files /dev/null and b/target/classes/META-INF/demo.kotlin_module differ diff --git a/target/classes/application.properties b/target/classes/application.properties index 56b652b..33a0b89 100644 --- a/target/classes/application.properties +++ b/target/classes/application.properties @@ -10,4 +10,6 @@ spring.h2.console.settings.web-allow-others=true spring.datasource.driver-class-name=org.postgresql.Driver spring.datasource.url=jdbc:postgresql://localhost:5432/test_db spring.datasource.username=postgres -spring.datasource.password=postgres \ No newline at end of file +spring.datasource.password=postgres + +jsonStoreEnabled=true \ No newline at end of file diff --git a/target/classes/com/example/demo/DemoApplication.class b/target/classes/com/example/demo/DemoApplication.class index 0fcc45f..6cdd1fd 100644 Binary files a/target/classes/com/example/demo/DemoApplication.class and b/target/classes/com/example/demo/DemoApplication.class differ diff --git a/target/classes/com/example/demo/controller/ViewController.class b/target/classes/com/example/demo/controller/ViewController.class new file mode 100644 index 0000000..01ecbf0 Binary files /dev/null and b/target/classes/com/example/demo/controller/ViewController.class differ diff --git a/target/classes/com/example/demo/entity/View.class b/target/classes/com/example/demo/entity/View.class new file mode 100644 index 0000000..ef0bf1a Binary files /dev/null and b/target/classes/com/example/demo/entity/View.class differ diff --git a/target/classes/com/example/demo/repository/ViewRepository.class b/target/classes/com/example/demo/repository/ViewRepository.class new file mode 100644 index 0000000..af3ebab Binary files /dev/null and b/target/classes/com/example/demo/repository/ViewRepository.class differ diff --git a/target/classes/com/example/demo/service/ViewService.class b/target/classes/com/example/demo/service/ViewService.class new file mode 100644 index 0000000..c45b0cb Binary files /dev/null and b/target/classes/com/example/demo/service/ViewService.class differ diff --git a/target/classes/twitter4j.properties b/target/classes/twitter4j.properties new file mode 100644 index 0000000..3f06541 --- /dev/null +++ b/target/classes/twitter4j.properties @@ -0,0 +1,5 @@ +debug=true +oauth.consumerKey= 53i2wkDRrQjw4zUkHdTpgxxTx +oauth.consumerSecret= dpgXNsrU8Tk2JZYG9tt6cVpHvcsGb7lq1RwxK2Ibe45aMV6eTT +oauth.accessToken= 211508041-Ut8dYloaixL0BKyJTvqluKak5VHFwMILZo3eyLDJ +oauth.accessTokenSecret= NkfQIRnHHaYMqJwrcVtjcshq7DKcdFVJteQkp4fXST6vl \ No newline at end of file diff --git a/target/test-classes/com/example/demo/DemoApplicationTests.class b/target/test-classes/com/example/demo/DemoApplicationTests.class index 5756833..27b8e18 100644 Binary files a/target/test-classes/com/example/demo/DemoApplicationTests.class and b/target/test-classes/com/example/demo/DemoApplicationTests.class differ