def post_microblog_post_on_twitter(microblog_post): api = Twitter(api_key=settings.TWITTER_API_KEY, api_secret=settings.TWITTER_API_SECRET, access_token=settings.TWITTER_ACCESS_TOKEN, access_token_secret=settings.TWITTER_ACCESS_TOKEN_SECRET) post_content = format_twitter_post(microblog_post) try: api.statuses_update().post(params={'status': post_content}) microblog_post.posted_on_twitter = True microblog_post.save() except ClientError: logger.error( "Tried to post a microblog post on Twitter but got a ClientError, " "check your twitter keys.") raise
class TestTapioca(unittest.TestCase): def setUp(self): self.wrapper = Twitter(api_key='api_key', api_secret='api_secret', access_token='access_token', access_token_secret='access_token_secret') def test_resource_access(self): resource = self.wrapper.statuses_mentions_timeline() self.assertEqual( resource.data, 'https://api.twitter.com/1.1/statuses/mentions_timeline.json')
class TestTapioca(unittest.TestCase): def setUp(self): self.wrapper = Twitter( api_key='api_key', api_secret='api_secret', access_token='access_token', access_token_secret='access_token_secret') def test_resource_access(self): resource = self.wrapper.statuses_mentions_timeline() self.assertEqual(resource.data(), 'https://api.twitter.com/1.1/statuses/mentions_timeline.json')
def generator_files(): with open('secrets.json') as secret_file: secret = json.load(secret_file) api = Twitter(api_key=secret['API_KEY'], api_secret=secret['API_SECRET'], access_token=secret['ACCESS_TOKEN'], access_token_secret=secret['ACCESS_TOKEN_SECRET']) channels = { 'fashions': ('theblondesalad', 'aimeesong', 'Kayture', 'GalMeetsGlam', 'wendynguyen'), 'fitness': ('greatist', 'dailyburn', 'FitBottomedGirl', '@bornfitness', 'TheRock') } for type_channel, values in channels.items(): for channel in values: tweets = api.search_tweets().get(params={ 'q': 'from:{channel}', 'count': 20, 'result_type': 'recent' }) data = tweets().data with open( "/tmp/files/tweets_{channel}.csv".format(channel=channel), 'w') as csvfile: fieldnames = ['id', 'text', 'user_name', 'user_id'] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() for item in data['statuses']: writer.writerow({ 'id': item['id'], 'text': item['text'], 'user_name': item['user']['name'], 'user_id': item['user']['id'] })
def twitter_crawler(user_name, **timeline_kwargs): api = Twitter(api_key=config['twitter']['api_key'], api_secret=config['twitter']['api_secret'], access_token=config['twitter']['access_token'], access_token_secret=config['twitter']['access_token_secret']) post_rows = get_twitter_posts(api, screen_name=user_name, **timeline_kwargs) file_path = 'raw_data/twitter_{}.csv'.format( datetime.now().isoformat().replace(':', '_')) write_post_csv(file_path, post_rows)
from decouple import config from tapioca_twitter import Twitter from tapioca.exceptions import TapiocaException api = Twitter( api_key=config('API_KEY'), api_secret=config('API_SECRET'), access_token=config('ACCESS_TOKEN'), access_token_secret=config('ACCESS_TOKEN_SECRET'), ) try: r = api.statuses_user_timeline().get(params={ 'screen_name': 'xima', 'count': 2 }) except TapiocaException as e: print e.client().data() print e.client().response().status_code
def setUp(self): twitter_api = Twitter() self.api_url = twitter_api.statuses_user_timeline().data
def setUp(self): twitter_api = Twitter() self.api_url = twitter_api.users_lookup().data
from decouple import config from tapioca_twitter import Twitter from tapioca.exceptions import TapiocaException api = Twitter(api_key=config('API_KEY'), api_secret=config('API_SECRET'), access_token=config('ACCESS_TOKEN'), access_token_secret=config('ACCESS_TOKEN_SECRET'),) try: r = api.statuses_user_timeline().get(params={'screen_name': 'xima', 'count': 2}) except TapiocaException as e: print e.client().data() print e.client().response().status_code
def setUp(self): self.wrapper = Twitter(api_key='api_key', api_secret='api_secret', access_token='access_token', access_token_secret='access_token_secret')
def setUp(self): self.wrapper = Twitter( api_key='api_key', api_secret='api_secret', access_token='access_token', access_token_secret='access_token_secret')