def __init__(self, user): api_key = config['auth']['twitter']['api_key'] secret_key = config['auth']['twitter']['secret_key'] # build client and class props self.client = Client(api_key, secret_key) self.user = user
def get_team_tweets(handle): twitter = Client(cfg.CONSUMER_KEY, cfg.CONSUMER_SECRET) tweets = twitter.request( 'https://api.twitter.com/1.1/statuses/user_timeline.json?count=3&screen_name=' + handle) return (jsonify(tweets)) # if __name__ == '__main__': # app.run(debug=True)
def gettweetsfromapi(messageBody): CONSUMER_KEY = getconsumerkey() CONSUMER_SECRET = getconsumersecret() client = Client(CONSUMER_KEY, CONSUMER_SECRET) hashtag = gethashtag(messageBody) tweet = client.request( 'https://api.twitter.com/1.1/search/tweets.json?q=' + hashtag + '&count=5&lang=en') status = client.rate_limit_status() print status['resources']['search'] return formattweet(tweet)
def twitter_search(search_string): CONSUMER_KEY = 'sbmaTK8blnFbLo4FeDxe6HkDm' CONSUMER_SECRET = 'aRgoP3t1BOs322MXDbyaVABH5Vfqjy44bKwur2r8UPkb6Ij1pH' client = Client(CONSUMER_KEY, CONSUMER_SECRET) tweets = client.request( "https://api.twitter.com/1.1/search/tweets.json?q={0}&result_type=recent" .format(search_string)) response = [] for index, tweet in enumerate(tweets['statuses']): url = "https://twitter.com/{0}/status/{1}".format( tweet['user']['screen_name'], tweet['id_str']) r = requests.get('https://publish.twitter.com/oembed?url=' + url) j = json.loads(r.text) response.append(j) if index >= 9: break return json.dumps(response)
def get_hashtees(search_phrase, since='2012-01-01'): search_phrase = search_phrase.replace(' ', '%20') search_phrase = search_phrase.replace('#', HASHTAG) client = Client(config.CONSUMER_KEY, config.CONSUMER_SECRET) if since is not None: since_ = "%20since:"+since else: since_ = '' tweet = client.request(TWTTR_API + TWTTR_API_VERSION + TWTTR_QUERY + search_phrase + '&' + TWTTR_RECENT) hashtags_ele = search(["hashtags"], tweet) actual_tags = search(["text"], hashtags_ele) catch_words = [] for tags in actual_tags: for k in tags: catch_words.append(tags[k]) return catch_words
import urllib.parse import boto3 import os from application_only_auth import Client from twittersearchhelpers import twitter_s3 base_search_url = 'https://api.twitter.com/1.1/search/tweets.json?count=%d&q=%s' COUNT = 5 # doing this outside the lambda is better for performance s3_client = boto3.client('s3') TWITTER_KEY = os.environ['TWITTER_KEY'] TWITTER_SECRET = os.environ['TWITTER_SECRET'] client = Client(TWITTER_KEY, TWITTER_SECRET) def get_tweet_text(tag): tweet_list = [] tag = urllib.parse.quote_plus(tag) url = base_search_url % (COUNT, tag) print('searching for ' + url) tweets = client.request(url) for status in tweets['statuses']: tweet = 'Tweet:' + status['text'] tweet_list.append(tweet) print('Found ' + str(tweet_list))
def __init__(self): self.client = Client(CONSUMER_KEY, CONSUMER_SECRET)
from datetime import datetime from urllib import parse from application_only_auth import Client import config client = Client(config.twitter_consumer_key, config.twitter_consumer_secret) def getTweets(q, cycles): res = { 'statuses': [] } tweets = [] earliest = datetime.now() for i in range(cycles): callRes = __getTweetsSingleCycle(q=q, untilDate=earliest) if (hasattr(res, 'search_metadata') == False): res['twitter_search_metadata'] = callRes['search_metadata'] tweets = tweets + callRes['statuses'] earliest = __getEarliestTweetDate(tweets=tweets) for tweet in tweets: res['statuses'].append({'tweet': tweet}) return res def getOneTweet(tweetId): query = {'id': tweetId} qs = parse.urlencode(query) url = 'https://api.twitter.com/1.1/statuses/show.json?' + qs return client.request(url)
from .forms import UserHandle import json from application_only_auth import Client import operator import matplotlib.pyplot as plt from matplotlib.backends.backend_agg import FigureCanvasAgg import pylab from matplotlib.figure import Figure from wordcloud import WordCloud from django.http import HttpResponse from urllib.parse import quote # Create your views here. CONSUMER_KEY = 'QjV8mWFAFl7DQ6UcRvnte0wEY' CONSUMER_SECRET = '2D2T2veOt5M0MqfliX7sI77zSpxT1kaHJvbYSYxgw3DFChpq3O' client = Client(CONSUMER_KEY, CONSUMER_SECRET) def home(request): form = UserHandle() if request.method == 'POST': form = UserHandle(request.POST) if form.is_valid(): global client user_handle = form.cleaned_data['handle'] url = 'https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name={}&count=1000'.format( user_handle) tweet = client.request(url) days = { 'Mon': 0, 'Tue': 0,
import os import json import html from application_only_auth import Client import indicoio as i import operator # Look around my environment for api keys CONSUMER_SECRET = os.environ["TWITTER_SECRET"] CONSUMER_KEY = os.environ["TWITTER_KEY"] INDICO_KEY = os.environ["INDICO_KEY"] # Create twitter and indico objects twitter = Client(CONSUMER_KEY, CONSUMER_SECRET) i.config.api_key = INDICO_KEY persona_mapping = { "architect": "intj", "logician": "intp", "commander": "entj", "debater": "entp", "advocate": "infj", "mediator": "infp", "protagonist": "enfj", "compaigner": "enfp", "logistician": "istj", "defender": "isfj", "executive": "estj", "consul": "esfj", "virtuoso": "istp", "adventurer": "isfp",
def __init__(self, user): # build client and class props self.client = Client(API_KEY, SECRET_KEY) self.user = user
def setUp(self): self.patcher = patch('application_only_auth.client.urlopen', fake_urlopen) self.patcher.start() self.client = Client('xxxxxx', 'xxxxxx')