2.1 Analysing Social Media in Python
2.1 Analysing Social Media in Python
Data
A N A LY Z I N G S O C I A L M E D I A D ATA I N P Y T H O N
Alex Hanna
Computational Social Scientist
Why Analyze Twitter Data?
Within a tweet
Text
Geolocation
Alex Hanna
Computational Social Scientist
Twitter API
API: Application Programming Interace
Method of accessing data
Twi er APIs
Search API
Ads API
Streaming API
Filter endpoint
Keywords
User IDs
Locations
Sample endpoint
Random sample
class SListener(StreamListener):
def __init__(self, api = None):
self.output = open('tweets_%s.json' %
time.strftime('%Y%m%d-%H%M%S'), 'w')
self.api = api or API()
...
listen = SListener(api)
stream = Stream(auth, listen)
stream.sample()
Alex Hanna
Computational Social Scientist
Contents of Twitter JSON
{ "created_at": "Thu Apr 19 14:25:04 +0000 2018",
"id": 986973961295720449,
"id_str": "986973961295720449",
"text": "Writing out the script of my @DataCamp class
and I can't help but mentally read it back to myself in
@hugobowne's voice.",
"retweet_count": 0,
"favorite_count": 1,
... }
Language
extended_tweet
tweets over 140 characters