Created
June 10, 2013 20:43
-
-
Save repustate/5752105 to your computer and use it in GitHub Desktop.
Data mining Twitter using Python and the Repustate Social API.
This file contains 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 json | |
import requests | |
API_KEY = 'YOUR_API_KEY' | |
BASE_URL = 'http://social.repustate.com/%(api_key)s/%(call)s.json' | |
# Create a new data source. | |
kwargs = {'api_key':API_KEY, 'call':'add-datasource'} | |
response = requests.post(BASE_URL % kwargs, {'name':'Testing', 'language':'en', 'niche':'general'}) | |
datasource_id = json.loads(response.content)['datasource_id'] | |
# Add a monitoring rule to our newly created data source. | |
kwargs['call'] = 'add-rule' | |
post_data = { | |
'datasource_id':datasource_id, | |
'source_type':'twitter-all', | |
'query':'iOS7', | |
'min_followers':1000, | |
'exclude_retweets':1 | |
} | |
response = requests.post(BASE_URL % kwargs, post_data) | |
# Assuming a little bit of time has passed and Repustate has collected data, we | |
# can now create a visualization. | |
# Let's generate a graph showing the breakdown of male vs. female for positive sentiment. | |
kwargs['call'] = 'visualize' | |
post_data = { | |
'datasource_id':datasource_id, | |
'since':'2013-06-01', | |
'until':'2014-01-01', | |
'filter_type':'gender', | |
'sentiment':'positive', | |
} | |
response = requests.post(BASE_URL % kwargs, post_data) | |
url = json.loads(response.content)['url'] | |
# Here's our URL, ready to download. | |
print url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment