Skip to content

Instantly share code, notes, and snippets.

@alfajrimutawadhi
Created January 31, 2023 03:20
Show Gist options
  • Save alfajrimutawadhi/5cd1c367eec3fcc5a81c2738140a5b33 to your computer and use it in GitHub Desktop.
Save alfajrimutawadhi/5cd1c367eec3fcc5a81c2738140a5b33 to your computer and use it in GitHub Desktop.
crawling tweets and proccess NLP
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"import tweepy\n",
"from textblob import TextBlob"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"# set requirement\n",
"# get your own key from https://developer.twitter.com/en/apps\n",
"consumer_key = \"< SECRET >\"\n",
"consumer_secret = \"< SECRET >\""
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"# login to API twitter\n",
"auth = tweepy.AppAuthHandler(consumer_key, consumer_secret)\n",
"api = tweepy.API(auth)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# docs of query : https://developer.twitter.com/en/docs/twitter-api/tweets/search/integrate/build-a-query\n",
"tweets = api.search_tweets(q=\"< QUERY >\", count=100)\n",
"for tweet in tweets:\n",
" analysis = TextBlob(tweet.text)\n",
" print(tweet.text+\" : \"+str(analysis.sentiment.polarity))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.4"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment