기본적으로 tweetfeels는 현재 디렉토리에 데이터베이스를 만듭니다. 다음에 프로그램을 시작하면 동일한 데이터베이스를 계속 사용하고 중단 한 부분부터 다시 시작합니다. tweetfeels가 키워드를 변경하는 데 어떤 영향을 미치는지는 모르겠지만 tweetfeels의 이러한 동작은 문제가 될 수 있습니다. 해결책은 다른 키워드에 대해 다른 데이터베이스를 사용한 다음 데이터베이스의 위치를 TweetFeels 생성자에 전달하는 것입니다.
Tweetfeels에 대해 많이 알지 못합니다. 흥미 롭기 때문에 프로젝트를 다운로드했으며, 필자가 제공하는 키워드에 대한 정서 분석을 수행하는 작업 스크립트가 있습니다. TweetFeels을 작동시키는 데 여전히 문제가 있다면 여기에 스크립트 사본을 추가 할 수 있습니다.
편집 : 나는 나는 현재 스크립트 다음과 같은 문제가 발생하고
를 사용하고 여기에 스크립트.
1) 내가 갖고있는 것과 다른 오류가 발생했지만, tweetfeels 라이브러리를 pip에서 Github 저장소의 최신 코드로 바꾸어서 문제를 해결할 수있었습니다.
2) 감정 수치가보고되지 않으면 ctrl + c 키보드 인터럽트를 강제로 보내지 않고 tweetfeels가 완전히 중지되지 않는 경우가 있습니다.
import os, sys, time
from threading import Thread
from pathlib import Path
from tweetfeels import TweetFeels
consumer_key = 'em...'
consumer_secret = 'aF...'
access_token = '25...'
access_token_secret = 'd3...'
login = [consumer_key, consumer_secret, access_token, access_token_secret]
try:
kw = sys.argv[1]
except IndexError:
kw = "iota"
try:
secs = int(sys.argv[2])
except IndexError:
secs = 15
for arg in sys.argv:
if (arg == "-h" or arg == "--help"):
print("Gets sentiment from twitter.\n"
"Pass in a search term, and how frequently you would like the sentiment recalculated (defaults to 15 seconds).\n"
"The keyword can be a comma seperated list of keywords to look at.")
sys.exit(0)
db = Path(f"~/tweetfeels/{kw}.sqlite").expanduser()
if db.exists():
print("existing db detected. Continueing from where the last sentiment stream left off")
else:
#ensure the parent folder exists, the db will be created inside of this folder
Path(f"~/tweetfeels").expanduser().mkdir(exist_ok=True)
feels = TweetFeels(login, tracking=kw.split(","), db=str(db))
go_on = True
def print_feels(feels, seconds):
while go_on:
if feels.sentiment:
print(f"{feels.sentiment.volume} tweets analyzed from {feels.sentiment.start} to {feels.sentiment.end}")
print(f'[{time.ctime()}] Sentiment Score: {feels.sentiment.value}')
print(flush=True)
else:
print(f"The datastream has not reported a sentiment value.")
print(f"It takes a little bit for the first tweets to be analyzed (max of {feels._stream.retry_time_cap + seconds} seconds).")
print("If this problem persists, there may not be anyone tweeting about the keyword(s) you used")
print(flush=True)
time.sleep(seconds)
t = Thread(target=print_feels, kwargs={"feels":feels,"seconds":secs}, daemon=True)
print(f'Twitter posts containing the keyword(s) "{kw}" will be streamed, and a new sentiment value will be recalculated every {secs} seconds')
feels.start()
time.sleep(5)
t.start()
try:
input("Push enter at any time to stop the feed...\n\n")
except (Exception, KeyboardInterrupt) as e:
feels.stop()
raise e
feels.stop()
go_on = False
print(f"Stopping feed. It may take up to {feels._stream.retry_time_cap} for the feed to shut down.\n")
#we're waiting on the feels thread to stop
안녕하세요! 스크립트를 복사 해 주시겠습니까? 많은 감사합니다 !! –
나는 지금 내 스크립트를 대답에 추가했다. –