Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed old methods and added queries as input from users #46

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
env/
45 changes: 27 additions & 18 deletions jobtweets.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self):
consumer_secret = 'XXXXXXXXXXXX'
access_token = 'XXXXXXXXXXXX'
access_token_secret = 'XXXXXXXXXXXX'


try:

Expand All @@ -25,6 +25,7 @@ def __init__(self):
self.auth.set_access_token(access_token, access_token_secret)

self.api = tweepy.API(self.auth)

except:
print("Error: Authentication Failed")

Expand Down Expand Up @@ -59,7 +60,7 @@ def get_tweets(self, query, count = 10):

try:

fetched_tweets = self.api.search(q = query, count = count)
fetched_tweets = self.api.search_tweets(q = query, count = count)


for tweet in fetched_tweets:
Expand All @@ -81,30 +82,38 @@ def get_tweets(self, query, count = 10):

return tweets

except tweepy.TweepError as e:
except tweepy.TweepyException as e:
print("Error : " + str(e))

def main():
api = TwitterClient()
tweets = api.get_tweets(query = 'Job Opportunities', count = 500)
ptweets = [tweet for tweet in tweets if tweet['sentiment'] == 'positive']

print("Positive tweets percentage: {} %".format(100*len(ptweets)/len(tweets)))

hashtags = input("Enter hashtags seperated by commas: (e.g jobs, openings, job opportunities) \n")
queries = [q.strip() for q in hashtags.split(",")]

ntweets = [tweet for tweet in tweets if tweet['sentiment'] == 'negative']
for query in queries:

print("Negative tweets percentage: {} %".format(100*len(ntweets)/len(tweets)))
tweets = api.get_tweets(query = query, count = 500)

print("Neutral tweets percentage: {} % ".format(100*(len(tweets) - len(ntweets) - len(ptweets))/len(tweets)))

print("\n\nPositive tweets:")
for tweet in ptweets[:10]:
print(tweet['text'])

print("\n\nNegative tweets:")
for tweet in ntweets[:10]:
print(tweet['text'])
ptweets = [tweet for tweet in tweets if tweet['sentiment'] == 'positive']

print("Positive tweets percentage: {} %".format(100*len(ptweets)/len(tweets)))

ntweets = [tweet for tweet in tweets if tweet['sentiment'] == 'negative']

print("Negative tweets percentage: {} %".format(100*len(ntweets)/len(tweets)))

print("Neutral tweets percentage: {} % ".format(100*(len(tweets) - len(ntweets) - len(ptweets))/len(tweets)))

print("\n\nPositive tweets:")
for tweet in ptweets[:10]:
print(tweet['text'])

print("\n\nNegative tweets:")
for tweet in ntweets[:10]:
print(tweet['text'])


if __name__ == "__main__":

main()
14 changes: 14 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
certifi==2021.5.30
charset-normalizer==2.0.6
click==8.0.1
idna==3.2
joblib==1.0.1
nltk==3.6.3
oauthlib==3.1.1
regex==2021.9.30
requests==2.26.0
requests-oauthlib==1.3.0
textblob==0.15.3
tqdm==4.62.3
tweepy==4.0.1
urllib3==1.26.7