Skip to content

Using various Python libraries such as Pandas, tweetPy, JSON ans matplotLib to take a sneak peek on your Twitter account using Google Colab.

License

Notifications You must be signed in to change notification settings

engali94/Twitter-Account-Analyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Twitter Account Data Analysis

Using various Python libraries such as Pandas, tweetPy, JSON and matplotLib to take a sneak peek on your Twitter account using Google Colab.

Setup

Open Google Colab and import the required Libs

    from google.colab import drive # to mount Google Drive to Colab notebook
    import tweepy # Python wrapper around Twitter API
    import json
    import pandas as pd
    import csv
    from datetime import date
    from datetime import datetime
    import time
    import matplotlib.pyplot as plt

Mounting Google Drive

create a new folder name it dataset then another inside it with twitter_analysis Yo can change the directory as you like

    drive.mount('/content/gdrive')
    path = './gdrive/My Drive/datasets/twitter_analysis/'
    #Follow the popup link and complete the autuorization  process

Twitter Data Collection

Login

In this section you need to get your Twitter API credentials then load Twitter API secrets from an external file

    secrets = json.loads(open(path + 'secrets.json').read())
    consumer_key = secrets['consumer_key']
    consumer_secret = secrets['consumer_secret']
    access_token = secrets['access_token']
    access_token_secret = secrets['access_token_secret']
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    api = tweepy.API(auth)

Helper Functions

  • save_json(file_name, file_content): Helper function to save data into a JSON file.
  • file_name: the name of the data file you want to save on your Google Drive
  • file_content: the data you want to save.
  • limit_handled(cursor, list_name) Helper function to handle twitter API rate limit.

Data Collection Functions

  • get_all_tweets(screen_name) : Helper function to get all tweets for a specified user and write it to a csv file.
  • todays_stats(dict_name) : Helper function to get today's numbers of followers and friends and store them into a JSON file.
  • get_followers(): Helper function to load follower objects into a list and save them into a JSON file.
  • get_friends(): Load friends into list

Analyzing tweets

  • Load saved data from Google Drive
  • Classify tweets

Classification

Other Features

  • Analyzing followers

  • Analyzing following

  • Analyzing History

About The Author

About

Using various Python libraries such as Pandas, tweetPy, JSON ans matplotLib to take a sneak peek on your Twitter account using Google Colab.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages