Browse Source

트위터 코드 추가

tobby48 5 years ago
parent
commit
fbe346c1b0

+ 9
- 1
src/main/java/kr/co/swh/lecture/opensource/twitter/TwitterBasic.java View File

@@ -52,6 +52,15 @@ public class TwitterBasic {
52 52
 	    }else{
53 53
 	    	//	Quiz.
54 54
 	    	// 	따로 만들어야 함. 트위터는 한번에 100개씩 제한
55
+	    	//	Status 클래스의 객체 내 id값을 통해 가능
56
+//	    	query.setCount(100);    //트위터 API 에서 한번에 가져올 수 있는 양이 100개
57
+//	    	long lowestStatusId = Long.MAX_VALUE;
58
+//	    	List<Status> statuses = this.getTweetBlock(query);
59
+//			for (Status status : statuses) {
60
+//				lowestStatusId = Math.min(status.getId(), lowestStatusId);
61
+//				result.add(status);
62
+//			}
63
+//			query.setMaxId(lowestStatusId - 1);
55 64
 	    }
56 65
 		return tweetList;
57 66
 	}
@@ -92,5 +101,4 @@ public class TwitterBasic {
92 101
         	//	VO 클래스로 객체형태로 변환하여 다양하게 활용
93 102
         }
94 103
 	}
95
-
96 104
 }

+ 0
- 1
src/main/java/kr/co/swh/lecture/opensource/twitter/TwitterStreaming.java View File

@@ -80,5 +80,4 @@ public class TwitterStreaming {
80 80
 	    // sample() method internally creates a thread which manipulates TwitterStream and calls these adequate listener methods continuously.
81 81
 	    twitterStream.sample("ko");
82 82
 	}
83
-
84 83
 }

+ 1
- 1
src/main/python/kr/co/swh/lecture/opensource/twitter/sample.json
File diff suppressed because it is too large
View File


+ 1
- 0
src/main/python/kr/co/swh/lecture/opensource/twitter/twitter_crawler_basic.py View File

@@ -1,4 +1,5 @@
1 1
 # https://marcobonzanini.com/2015/03/02/mining-twitter-data-with-python-part-1/comment-page-1/
2
+# conda install -c conda-forge tweepy
2 3
 import tweepy
3 4
 from tweepy import OAuthHandler
4 5
 import json

+ 4
- 9
src/main/python/kr/co/swh/lecture/opensource/twitter/twitter_crawler_streaming.py View File

@@ -1,5 +1,4 @@
1 1
 # https://imasoftwareengineer.tistory.com/97?category=791547
2
-# conda install -c conda-forge tweepy
3 2
 import tweepy
4 3
 from tweepy.streaming import StreamListener
5 4
 from tweepy import OAuthHandler
@@ -16,14 +15,10 @@ access_secret = 'xx'
16 15
 # 리스너 - 스트리밍 API로 부터 값이 들어오면 아래의 리스너가 실행된다.
17 16
 class Listener(StreamListener):
18 17
     def on_data(self, data):
19
-        try:
20
-            with open('sample.json', 'a', encoding='utf-8') as f:
21
-                json_data = json.loads(data)    # str -> json으로 변환
22
-                json.dump(json_data, f, ensure_ascii=False) # json을 원형 그대로 파일에 저장(인코딩 깨짐을 방지)
23
-                print(json_data)
24
-                return True
25
-        except BaseException as e:
26
-            print("Error on_data: %s" % str(e))
18
+        with open('sample.json', 'a', encoding='utf-8') as f:
19
+            json_data = json.loads(data)    # str -> json으로 변환
20
+            json.dump(json_data, f, ensure_ascii=False) # json을 원형 그대로 파일에 저장(인코딩 깨짐을 방지)
21
+            print(json_data)
27 22
         return True
28 23
 
29 24
     def on_error(self, status):