|
@@ -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):
|