Exactly, I think about the same. Or for having good impact in your products ( social media) if you're trying to sell stuff. There are many possibilities.
A project in mind is to just work in this kind of analysis for suicide prevention. π
Nice, very interesting! He seems to tweet surprisingly a high count of positive tweets (51%). But how much of this tweets are fake news and lies is another question... nytimes.com/interactive/2017/06/23...
Yeah, that resulted surprising to me! I've heard that he's not the only one tweeting from his account, but he has a team for this. That might be a possible reason. That's why it results interesting to analyze the polarity of tweets that come from different sources.
Well technically these sentiment calculations should be taken with a grain of salt. you use VaderSentiment library as well and compare both values of sentiments to get better insight.
After graduating from The George Washington University with a Bachelor of Business Administration in International Business, I began my career as an asset management intern for the Real Estate Fina...
Hi there, I was having some trouble with the "visualizing the statistics" section as detailed in sections 2.1 and 2.2; if you take a look at my GitHub repo, you'll notice I had to comment out # %matplotlib inline and replaced requirement with plt.ion() within the script-running file (trumpet.py) in order to run the scripts without failure (e.g. python3 trumpet.py). Can you please explain how to generate the visualizations as detailed in those sections? For some reason, I'm unable to render those visual within my Jupyter Notebook-env/config. I'm only 10 days new to Python, so I'd appreciate any guidance. Great tutorial-
thanks!
Instead of adding plt.ion() at the beginning, you can add the following code each time you're generating a plot, in order to visualize it: plt.show(). This will open an external window and display the immediately last plot generated.
After graduating from The George Washington University with a Bachelor of Business Administration in International Business, I began my career as an asset management intern for the Real Estate Fina...
Thank you for your tutorial! Its was easy to follow and everything work on my first attempt!
I do not want to reload all the tweets from the web, while I am developing. I altered the first few lines, to cache the tweets locally.
save = "saved.pickle"
if os.path.exists(os.path.join(os.path.dirname(__file__), save)):
with open(save, 'rb') as f:
tweets = pickle.load(f)
else:
extractor = twitter_setup()
tweets = extractor.user_timeline(screen_name="realDonaldTrump", count=200)
with open(save, 'wb') as f:
pickle.dump(tweets, f)
What I did at the end (in my personal case) was to save the tweet list as a csv file (data.to_csv(...)), taking as an advantage that I already had all the info in a pandas dataframe. :)
Nicely done. I had installed Anaconda before but didn't really get past Hello World in the Jupyter notebook. This was an excellent idea to get people like me off their proverbial rear-end and use it for a very fun idea! I was able to follow it right through and get everything to work after dusting off the cobwebs of my Anaconda environment.
One of my ideas about this post is to give tools to implement solutions on different areas. As you say, this could help in healthcare analysis. For that you might need a specific classifier (not the texblob's default I used), and you can learn how to build one in the last reference I provide in the post.
If you begin working on that, please let us know if there's a thing on which we may help.
Would it be possible to check / detect how many likes comes from the staff of a VIP ? It is said that many politicals manage likes and retweets by asking their support to like and retweet their messages? (not sure to be clear) Through 200 tweets, this would be possible to look at the twitter accounts that like systematically and quickly (as soon as published, like bots do) then substract (or minimize) them from the final evaluation.
If you want to count something like this in real time, you would need to modify the way you're consuming the API (rest) and create a listener (you can still do that with Tweepy). That's what I would do, I'd create a specific listener for Trump's tweets and use threads to count for certain time likes and retweets for a new tweet.
Does this answer help? I can try to be more explicit. :)
A software developer, mainly worked on OCR based application development, developed many Tk based GUI front end tools, started learning Python, and developed many bots.
Consume as a Rest API. In that case, the deployment in Heroku (or any other deployment service) would have to process the new tweets and add the new data to the previous.
Create a stream listener to continuously detect a new tweet and process it.
In 1., the simplest way would be only to schedule a task (a simple script) to be executed on certain time (pythonanywhere also works for this, I have a twitter bot that runs every 24 hours). Anyway one can create a service using Tweepy, in fact there's a Flask-Tweepy integration: flask-tweepy.readthedocs.io/en/lat...
ModuleNotFoundError Traceback (most recent call last)
in ()
1 # We import our access keys:
----> 2 from credentials import * # This will allow us to use the keys as variables
3
4 # API's setup:
5 def twitter_setup():
ModuleNotFoundError: No module named 'credentials'
Oldest comments (97)
Fascinating. I wouldn't be surprised if this kind of research goes mainstream in the future in journalism.
Exactly, I think about the same. Or for having good impact in your products ( social media) if you're trying to sell stuff. There are many possibilities.
A project in mind is to just work in this kind of analysis for suicide prevention. π
Nice, very interesting! He seems to tweet surprisingly a high count of positive tweets (51%). But how much of this tweets are fake news and lies is another question... nytimes.com/interactive/2017/06/23...
Yeah, that resulted surprising to me! I've heard that he's not the only one tweeting from his account, but he has a team for this. That might be a possible reason. That's why it results interesting to analyze the polarity of tweets that come from different sources.
Well technically these sentiment calculations should be taken with a grain of salt. you use VaderSentiment library as well and compare both values of sentiments to get better insight.
Excelente trabajo Rodolfo para NLP. Saludos un abrazo
MuchΓsimas gracias. Como mencionaba en el post, en mi Github puede encontrarse el notebook con el contenido en espaΓ±ol (por cualquier cosa).
Β‘Saludos!
Hi there, I was having some trouble with the "visualizing the statistics" section as detailed in sections 2.1 and 2.2; if you take a look at my GitHub repo, you'll notice I had to comment out #
%matplotlib inline
and replaced requirement withplt.ion()
within the script-running file (trumpet.py) in order to run the scripts without failure (e.g.python3 trumpet.py
). Can you please explain how to generate the visualizations as detailed in those sections? For some reason, I'm unable to render those visual within my Jupyter Notebook-env/config. I'm only 10 days new to Python, so I'd appreciate any guidance. Great tutorial-thanks!
Sure! It's quite easy actually. :)
Instead of adding
plt.ion()
at the beginning, you can add the following code each time you're generating a plot, in order to visualize it:plt.show()
. This will open an external window and display the immediately last plot generated.You can see this in the Official Pyplot tutorial I shared at the end (References).
Please let me know I you have any other problem. :)
Got it, Rodolfo! Thank you for the guidance- tremendous fun! ;)
Awesome tutorial!!
Thank you so much! πππΌ
Thank you for your tutorial! Its was easy to follow and everything work on my first attempt!
I do not want to reload all the tweets from the web, while I am developing. I altered the first few lines, to cache the tweets locally.
Excellent idea!
What I did at the end (in my personal case) was to save the tweet list as a csv file (
data.to_csv(...)
), taking as an advantage that I already had all the info in a pandas dataframe. :)Thanks for your great comment!
Nicely done. I had installed Anaconda before but didn't really get past Hello World in the Jupyter notebook. This was an excellent idea to get people like me off their proverbial rear-end and use it for a very fun idea! I was able to follow it right through and get everything to work after dusting off the cobwebs of my Anaconda environment.
Thanks for sharing!
Thank you so much! I really appreciate it.
I'll try to keep posting stuff like this, I enjoy doing applied things with Python. :)
One of my ideas about this post is to give tools to implement solutions on different areas. As you say, this could help in healthcare analysis. For that you might need a specific classifier (not the texblob's default I used), and you can learn how to build one in the last reference I provide in the post.
If you begin working on that, please let us know if there's a thing on which we may help.
Best!
Would it be possible to check / detect how many likes comes from the staff of a VIP ? It is said that many politicals manage likes and retweets by asking their support to like and retweet their messages? (not sure to be clear) Through 200 tweets, this would be possible to look at the twitter accounts that like systematically and quickly (as soon as published, like bots do) then substract (or minimize) them from the final evaluation.
This is an interesting question.
If you want to count something like this in real time, you would need to modify the way you're consuming the API (rest) and create a listener (you can still do that with Tweepy). That's what I would do, I'd create a specific listener for Trump's tweets and use threads to count for certain time likes and retweets for a new tweet.
Does this answer help? I can try to be more explicit. :)
Yes I understand the idea. This would be a very useful tool to track false popular account.
This might help: github.com/RodolfoFerro/TwitterBot...
You can find more info in the documentation: tweepy.readthedocs.io/en/v3.5.0/st...
Hope this complements my previous answer! ππΌ
Excellent, Superb man you are! Executed your code., got the results as it is.
Thanks!
I'm glad you enjoyed it. :)
nice
Thank you!
How do I take this to Cloud? flask + Heroku ??. Thanx in ADVANCE !!
Sorry for taking so long.
There are mainly two approaches:
In 1., the simplest way would be only to schedule a task (a simple script) to be executed on certain time (pythonanywhere also works for this, I have a twitter bot that runs every 24 hours). Anyway one can create a service using Tweepy, in fact there's a Flask-Tweepy integration: flask-tweepy.readthedocs.io/en/lat...
Thank you.
why am i getting this error:
ModuleNotFoundError Traceback (most recent call last)
in ()
1 # We import our access keys:
----> 2 from credentials import * # This will allow us to use the keys as variables
3
4 # API's setup:
5 def twitter_setup():
ModuleNotFoundError: No module named 'credentials'
I think that this will solve your error:
credentials.py
that has to contain your Twitter App credentials.Please let me know if not. :+1:
thank you very much. i solved that
Hi! Thanks for the tutorial.
I noticed that tweets containing RTs are not printed in full. How do I get the full RT text?
I am able to un-trunctate a tweet using this:
if tweet['truncated']:
tweet_text = tweet['extended_tweet']['full_text']
else:
tweet_text = tweet['text']
but it won't work for tweets containing RTs.
Anyone know how I can get the full RTs?
I would need it to get an accurate sentiment analysis.
Many thanks for the help!
Hi!
One possible approach would be adding the
tweet_mode
parameter as follows:Let me know if that does the trick. :)
Is all this code placed in one document? Or is everything separate? Sorry Iβm new to this, but need to do it as part of my project.
Thanks.
You can use one Jupyter Notebook, this might be useful: github.com/RodolfoFerro/pandas_twi...
Some comments may only be visible to logged-in visitors. Sign in to view all comments.