-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitterCrypto.py~
53 lines (43 loc) · 1.92 KB
/
twitterCrypto.py~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
import sys
import tweepy
import requests
import numpy as np
import textblob
#from keras.models import Sequential
#from keras.layers import Dense
#from textblob import TextBlob
consumer_key = 'E3xLP2DJVCojAuRc4dsIQhOhH'
consumer_secret = '46e1t5l5uZDUY3WfuNf0NwzsNVdPnJS7qtVjVc6HKwxfH0BYX4'
access_token = '398425873-SL80lXVpCqZN8zTTNWSz6pBWRdy1CwzdWQlRrBEu'
access_token_secret = 'FAmHxrdwJfnrcjRVKvuxVRpoQfezjS7npTc6dH20EfwAq'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
#now since we have the api variable we can create tweets delete tweets and find twitter users
userApi = tweepy.API(auth)
def stock_sentiment(quote, num_tweets):
# Checks if the sentiment for our quote is
# positive or negative, returns True if
# majority of valid tweets have positive sentiment
list_of_tweets = userApi.search(quote, count=num_tweets)
positive, objective, neg, sub = 0, 0, 0, 0
for tweet in list_of_tweets:
blob = textblob.TextBlob(tweet.text).sentiment
#The polarity score is a float within the range [-1.0, 1.0]. The subjectivity is a float within the range [0.0, 1.0] where 0.0 is very objective and 1.0 is very subjective.
if blob.subjectivity == 0:
objective += 1
#next
if blob.polarity > 0:
positive += 1
if blob.polarity < 0:
neg += 1
if blob.subjectivity == 1:
sub +=1
score = positive / ((num_tweets - objective)/2)
print("how its doing ",score)
print("values pos", positive, "negative values ", neg)
print("how many objective tweets ",objective, "num of subjective tweets", sub)
print("total tweets analyzed was ", num_tweets)
if positive > ((num_tweets - objective)/2):
return print("true")
stock_sentiment('ethereum', 100000)