[14.10.20] Testing
This commit is contained in:
parent
ab669a1ed7
commit
8e15f8c9f8
@ -23,6 +23,7 @@ from urllib3.exceptions import ProtocolError
|
|||||||
|
|
||||||
hourStack = []
|
hourStack = []
|
||||||
dumpStack = []
|
dumpStack = []
|
||||||
|
processStack = []
|
||||||
|
|
||||||
class keys():
|
class keys():
|
||||||
|
|
||||||
@ -67,7 +68,7 @@ class Streamer():
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
stream = Stream(auth=api.auth, listener=listener, tweet_mode='extended')
|
stream = Stream(auth, listener=listener, tweet_mode='extended')
|
||||||
stream.filter(languages=["en"], track=hashtag)
|
stream.filter(languages=["en"], track=hashtag)
|
||||||
except IncompleteRead:
|
except IncompleteRead:
|
||||||
log("Incomplete Read Error", 'ERR')
|
log("Incomplete Read Error", 'ERR')
|
||||||
@ -75,9 +76,6 @@ class Streamer():
|
|||||||
except ProtocolError:
|
except ProtocolError:
|
||||||
log("Protocol Error", 'ERR')
|
log("Protocol Error", 'ERR')
|
||||||
continue
|
continue
|
||||||
except:
|
|
||||||
log("Some other Error", 'ERR')
|
|
||||||
continue
|
|
||||||
|
|
||||||
class Listener(StreamListener):
|
class Listener(StreamListener):
|
||||||
|
|
||||||
@ -91,73 +89,63 @@ class Listener(StreamListener):
|
|||||||
if (time() - self.start_time) < self.limit:
|
if (time() - self.start_time) < self.limit:
|
||||||
data = json.loads(data)
|
data = json.loads(data)
|
||||||
|
|
||||||
|
log(len(dumpStack), 'INFO')
|
||||||
|
|
||||||
# Check if tweet is a retweet
|
# Check if tweet is a retweet
|
||||||
if 'retweeted_status' in data:
|
if 'retweeted_status' in data:
|
||||||
if 'extended_tweet' in data['retweeted_status']:
|
if 'extended_tweet' in data['retweeted_status']:
|
||||||
#if tweet is over the 140 word limit
|
#if tweet is over the 140 word limit
|
||||||
text = data['retweeted_status']['extended_tweet']['full_text']
|
text = data['retweeted_status']['extended_tweet']['full_text']
|
||||||
processTweet(text, self.hashtag)
|
dumpStack.append({'type': self.hashtag, 'tweet': text})
|
||||||
# dumpStack.append({'type': self.hashtag, 'tweet': text})
|
|
||||||
else:
|
else:
|
||||||
text = data['retweeted_status']['text']
|
text = data['retweeted_status']['text']
|
||||||
processTweet(text, self.hashtag)
|
dumpStack.append({'type': self.hashtag, 'tweet': text})
|
||||||
# dumpStack.append({'type': self.hashtag, 'tweet': text})
|
|
||||||
else:
|
else:
|
||||||
# Else if a normal Tweeet
|
# Else if a normal Tweeet
|
||||||
if 'extended_tweet' in data:
|
if 'extended_tweet' in data:
|
||||||
# If tweet is over 140 word limit
|
# If tweet is over 140 word limit
|
||||||
text = data['extended_tweet']['full_text']
|
text = data['extended_tweet']['full_text']
|
||||||
processTweet(text, self.hashtag)
|
dumpStack.append({'type': self.hashtag, 'tweet': text})
|
||||||
# dumpStack.append({'type': self.hashtag, 'tweet': text})
|
|
||||||
else:
|
|
||||||
processTweet(data["text"], self.hashtag)
|
|
||||||
|
|
||||||
def processTweet(text, type):
|
def processTweet():
|
||||||
|
|
||||||
log("hourStack size :: [{}]".format(len(hourStack)), "INFO")
|
processStack = dumpStack.copy()
|
||||||
|
dumpStack.clear()
|
||||||
|
|
||||||
log("Processing [{}] Tweet...".format(text), 'INFO')
|
# log("Processing [{}] Tweet...".format(text), 'INFO')
|
||||||
|
|
||||||
removedLines = fixLines(text)
|
if len(processStack) != 0:
|
||||||
log("fixLines", 'DEBUG')
|
for tweet in processStack:
|
||||||
|
|
||||||
removedSpecialChars = cleanTweet(removedLines)
|
removedLines = fixLines(str(tweet))
|
||||||
log("cleanTweet", 'DEBUG')
|
|
||||||
removedSpacing = removeSpacing(removedSpecialChars[0])
|
|
||||||
log("removeSpacing", 'DEBUG')
|
|
||||||
|
|
||||||
tweetLength = checkLength(removedSpacing)
|
removedSpecialChars = cleanTweet(removedLines)
|
||||||
log("checkLength", 'DEBUG')
|
removedSpacing = removeSpacing(removedSpecialChars[0])
|
||||||
if tweetLength == True:
|
|
||||||
|
|
||||||
checkIfEnglish = detectLaguage(removedSpecialChars[0])
|
tweetLength = checkLength(removedSpacing)
|
||||||
log("Boop2", 'DEBUG')
|
if tweetLength == True:
|
||||||
|
|
||||||
if checkIfEnglish == True:
|
checkIfEnglish = detectLaguage(removedSpecialChars[0])
|
||||||
|
|
||||||
tweetText = remove_non_ascii(removedSpacing)
|
if checkIfEnglish == True:
|
||||||
log("Boop3", 'DEBUG')
|
|
||||||
|
|
||||||
# log("Cleaned Tweet: {}".format(tweetText), 'INFO')
|
tweetText = remove_non_ascii(removedSpacing)
|
||||||
|
|
||||||
cleanedTweet = tweetText + ' ' + removedSpecialChars[1]
|
# log("Cleaned Tweet: {}".format(tweetText), 'INFO')
|
||||||
|
|
||||||
if callSpamFilter(cleanedTweet) != 'spam':
|
cleanedTweet = tweetText + ' ' + removedSpecialChars[1]
|
||||||
log("After spam call", 'DEBUG')
|
|
||||||
|
|
||||||
pos, neu, neg, compound = callSentimentAnalyser(cleanedTweet)
|
if callSpamFilter(cleanedTweet) != 'spam':
|
||||||
|
|
||||||
log("After Sentiment Call", 'DEBUG')
|
pos, neu, neg, compound = callSentimentAnalyser(cleanedTweet)
|
||||||
|
|
||||||
if compound != 0.0 | neu <= 0.8:
|
if compound != 0.0 or neu <= 0.8:
|
||||||
log("if not 0.0 or above 0.8", 'DEBUG')
|
hourTweet = {'pos': 1, 'neu': 1, 'neg': 1, 'compound': 1, 'type': ""}
|
||||||
|
|
||||||
hourTweet = {'pos': pos, 'neu': neu, 'neg': neg, 'compound': compound, 'type': type}
|
hourStack.append(hourTweet)
|
||||||
|
processStack.clear()
|
||||||
hourStack.append(hourTweet)
|
else:
|
||||||
# processStack.clear()
|
log("Dump Stack was Empty", 'WARN')
|
||||||
# else:
|
|
||||||
# log("Dump Stack was Empty", 'WARN')
|
|
||||||
|
|
||||||
def collector(hashtag):
|
def collector(hashtag):
|
||||||
|
|
||||||
@ -183,11 +171,15 @@ def createHourJob():
|
|||||||
log("Creating hour job...", 'INFO')
|
log("Creating hour job...", 'INFO')
|
||||||
schedule.clear("sendToArtemis")
|
schedule.clear("sendToArtemis")
|
||||||
ovPos, ovNeu, ovNeg, ovCompound = 0, 0, 0, 0
|
ovPos, ovNeu, ovNeg, ovCompound = 0, 0, 0, 0
|
||||||
|
type = ""
|
||||||
|
|
||||||
global timeF
|
global timeF
|
||||||
timeF = timeFunction()
|
timeF = timeFunction()
|
||||||
|
|
||||||
|
processTweet()
|
||||||
|
|
||||||
processStack = hourStack.copy()
|
processStack = hourStack.copy()
|
||||||
|
hourStack.clear()
|
||||||
|
|
||||||
log("Extracting sentiment scores...", 'INFO')
|
log("Extracting sentiment scores...", 'INFO')
|
||||||
|
|
||||||
@ -208,7 +200,7 @@ def createHourJob():
|
|||||||
if type == "bitcoin":
|
if type == "bitcoin":
|
||||||
type = 'btc_usd'
|
type = 'btc_usd'
|
||||||
|
|
||||||
hourStack.clear()
|
processStack.clear()
|
||||||
|
|
||||||
sendToArtemis(pos, neu, neg, compound, type)
|
sendToArtemis(pos, neu, neg, compound, type)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user