def streaming(credentials, coins, queries, refresh, path, realtime=False, logTracker=True, logTweets=True, logSentiment=False, debug=True):
# User Error Checks
if len(coins) <= 0: print("Error: You must include at least one coin."); return
if len(coins) >= 10: print("Warning: Fewer than ten coins recommended.")
if len(queries) <= 0: print("Error: You must include at least one query."); return
if len(queries) >= 20: print("Warning: Fewer than twenty queries recommended.")
if refresh <= 0: print("Error: Refresh rate must be greater than 0"); return
auth = tweepy.OAuthHandler(credentials[0], credentials[1])
auth.set_access_token(credentials[2], credentials[3])
if logSentiment:
global SentimentIntensityAnalyzer
from nltk.sentiment.vader import SentimentIntensityAnalyzer
while True:
# Start streaming -----------------------------
try:
print("Streaming Now...")
listener = CoinListener(auth, coins, queries, refresh, path, realtime, logTracker, logTweets, logSentiment, debug)
stream = tweepy.Stream(auth, listener)
stream.filter(track=queries)
except (Timeout, ConnectionError, ReadTimeoutError):
print("Reestablishing Connection...")
with open("%sError_Log.txt" % path, "a") as outfile:
outfile.write("%s Error: Connection Dropped\n" % time.strftime('%m/%d/%Y %H:%M'))
time.sleep((15*60)+1) # Wait at least 15 minutes before restarting listener
# ---------------------------------------------
评论列表
文章目录