evoclusterstream.stream package

Submodules

evoclusterstream.stream.TweepyStreamer module

From the paper: Evolutionary Clustering and Community Detection Algorithms for Social Media Health Surveillance

Kyle Spurlock, Tanner Bogart, Heba Elgazzar 2020

Notes

Requires Twitter API keys and tokens Retrieve from here https://developer.twitter.com

Current configuration collects user geographical location based on tweet keywords.

evoclusterstream.stream.TweepyStreamer.data

Data stream of uscities csv file

Type

:obj:stream

evoclusterstream.stream.TweepyStreamer.uscities

DataFrame of uscities csv file

Type

pd.DataFrame

Example

search_terms = [‘tweet1’, ‘tweet2’]

consumer_key = “your_consumer_key” consumer_secret_key = “your_consumer_secret_key”

access_token = “your_access_token” access_token_secret = “your_access_token_secret”

Streamer = TweepyStreamer(consumer_key, consumer_secret_key, access_token,

access_token_secret)

user info = Streamer.stream_tweets(search_terms, n_samples = 100)

class evoclusterstream.stream.TweepyStreamer.TweepyStreamer(consumer_key, consumer_secret, access_token, access_secret, *, wait_on_rate_lim=True, wait_on_rate_lim_notify=True)[source]

Bases: object

Class implementation for Twitter Streamer

auth

Tweepy OAuthHandler class, authorizes API with keys.

Type

:obj:Tweepy.OAuthHandler

api

Provides access to RESTful Twitter API.

Type

:obj:Tweepy.API

wait_on_rate_lim

Specifies whether to sleep upon reaching max stream requests.

Type

bool, optional

wait_on_rate_lim_notify

Verbose for wait_on_rate_lim

Type

bool, optional

stream_tweets(search_terms, n_samples, verbose=True)[source]

Method for accessing Twitter stream API using Tweepy Cursor

Parameters
  • search_terms (list) – Array of keywords to search for in tweets

  • n_samples (int) – Number of samples total to collect

  • verbose (bool, optional) – Controls console outputs

Returns

Contains information from found tweets

Return type

pd.DataFrame

evoclusterstream.stream.TweepyStreamer.full_preprocess(df)[source]

Preprocesses and saves dataset as csv

evoclusterstream.stream.TweepyStreamer.location_change(location, uscities)[source]

Expands verified location to include state and coordinate elements

evoclusterstream.stream.TweepyStreamer.location_verify(location, uscities)[source]

Performs match of user location to US Cities database

Module contents