Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
83 lines (66 sloc) 2.52 KB
import tweepy
import yaml
import plotly
from tweepy import OAuthHandler
from pandas import DataFrame
# Generic Twitter Class for sentiment analysis.
class TwitterClient(object):
def __init__(self):
res = {}
# Reading the secret values from a local disk
with open("../../../secret/twitter.yaml", 'r') as stream:
res= yaml.load(stream)
except yaml.YAMLError as exc:
consumer_key = res['apiKey']
consumer_secret = res['apiSecretKey']
access_token = res['accessToken']
access_token_secret = res['accessSecretToken']
# attempt authentication
# create OAuthHandler object
auth = OAuthHandler(consumer_key, consumer_secret)
# set access token and secret
auth.set_access_token(access_token, access_token_secret)
# create tweepy API object to fetch tweets
self.__api = tweepy.API(auth)
print("Error: Authentication Failed")
def get_government_members(self):
lists = self.__api.lists_all('SoMePolis')
for list in lists:
if == 'BundesparlamentarierInnen':
result = []
for item in tweepy.Cursor(self.__api.list_members,
return result
return None
def create_plotly_table(self):
lists = self.get_government_members()
labels = range(0,len(lists))
col1 = [list.screen_name for list in lists]
col2 = [ for list in lists]
col3 = [list.description for list in lists]
col4 = [list.followers_count for list in lists]
col5 = [list.friends_count for list in lists]
# Panda Data Set
panda_data = { 'ScreenName' : col1,
'Name': col2,
'Description': col3,
"FollowersCount": col4,
"FriendsCount": col5
df = DataFrame(panda_data , index=labels)
trace = plotly.graph_objs.Table(
header = dict(values=list(df.columns)),
cells = dict(values=[df.ScreenName, df.Name, df.Description, df.FollowersCount, df.FriendsCount]))
data = [trace]
plotly.plotly.plot(data, filename='pandas_table')
def main():
api = TwitterClient()
if __name__ == '__main__':
You can’t perform that action at this time.