This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!usr/bin/python | |
| import mysql.connector | |
| from mysql.connector import Error | |
| import tweepy | |
| import json | |
| from dateutil import parser | |
| import time | |
| import os | |
| import subprocess |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!usr/bin/python | |
| import mysql.connector | |
| from mysql.connector import Error | |
| import tweepy | |
| import json | |
| from dateutil import parser | |
| import time | |
| import os | |
| import subprocess |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def connect(username, created_at, tweet, retweet_count, place , location): | |
| """ | |
| connect to MySQL database and insert twitter data | |
| """ | |
| try: | |
| con = mysql.connector.connect(host = 'localhost', | |
| database='twitterdb', user='root', password = password, charset = 'utf8') | |
| if con.is_connected(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Streamlistener(tweepy.StreamListener): | |
| def on_connect(self): | |
| print("You are connected to the Twitter API") | |
| def on_error(self): | |
| if status_code != 200: | |
| print("error found") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if __name__== '__main__': | |
| auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
| auth.set_access_token(access_token, access_token_secret) | |
| api =tweepy.API(auth, wait_on_rate_limit=True) | |
| # create instance of Streamlistener | |
| listener = Streamlistener(api = api) | |
| stream = tweepy.Stream(auth, listener = listener) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import mysql.connector | |
| from mysql.connector import Error | |
| import os | |
| import re | |
| import pandas as pd | |
| from nltk.tokenize import word_tokenize | |
| from nltk.corpus import stopwords | |
| from nltk.stem.porter import PorterStemmer | |
| from nltk.stem import WordNetLemmatizer | |
| import nltk |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def clean_tweets(self, df): | |
| """ | |
| Takes raw tweets and cleans them | |
| so we can carry out analysis | |
| remove stopwords, punctuation, | |
| lower case, html, emoticons. | |
| This will be done using Regex | |
| ? means option so colou?r matches | |
| both color and colour. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def sentiment(self, tweet): | |
| """ | |
| This function calculates sentiment | |
| from our base on our cleaned tweets. | |
| Uses textblob to calculate polarity. | |
| Parameters: | |
| ---------------- | |
| arg1: takes in a tweet (row of dataframe) | |
| ---------------- | |
| Returns: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if __name__ == '__main__': | |
| t = TweetObject( host = 'localhost', database = 'twitterdb', user = 'root') | |
| data = t.MySQLConnect("SELECT created_at, tweet FROM `TwitterDB`.`Golf`;") | |
| data = t.clean_tweets(data) | |
| data['Sentiment'] = np.array([t.sentiment(x) for x in data['clean_tweets']]) | |
| t.word_cloud(data) | |
| t.save_to_csv(data) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import mysql.connector | |
| from mysql.connector import Error | |
| import os | |
| import re | |
| import pandas as pd | |
| from nltk.tokenize import word_tokenize | |
| from nltk.corpus import stopwords | |
| from nltk.stem import WordNetLemmatizer | |
| import nltk | |
| from wordcloud import WordCloud, STOPWORDS |
OlderNewer