Skip to content

Instantly share code, notes, and snippets.

@PandaWhoCodes
Created February 7, 2020 06:52
Show Gist options
  • Save PandaWhoCodes/bb2801f29605c39a6dd336ee2a09c4ae to your computer and use it in GitHub Desktop.
Save PandaWhoCodes/bb2801f29605c39a6dd336ee2a09c4ae to your computer and use it in GitHub Desktop.
API access for Tweet Assistant - Note: Make sure you register at TA before using the API
API_ENDPOINT = "https://tweetassistant.infoassistants.com"
from constants import API_ENDPOINT
import requests
username = "ashish_che"
# replace with your twitter ID which you have used to register in TweetAssistant
def get_summary(query):
"""
call the summary API for a given query
:param query: @user or a normal search terms
:return: list of top tweets,mentions and hashtags
"""
response = requests.get(API_ENDPOINT + '/get_summary', params={'query': query, "username": username})
return response.json()
def get_hashtags(query):
"""
call the get_hashtags API for a given query and recieves only the hashtags
:param query: @user or a normal search terms
:return: list of hashtags
"""
response = requests.get(API_ENDPOINT + '/get_hashtags', params={'query': query, "username": username})
return response.json()
def get_mentions(query):
"""
call the get_mentions API for a given query and recieves only the mentions
:param query: @user or a normal search terms
:return: list of mentions
"""
response = requests.get(API_ENDPOINT + '/get_mentions', params={'query': query, "username": username})
return response.json()
def get_text(query):
"""
call the get_text API for a given query and a string of all the tweet text for NLP purposes
:param query: @user or a normal search terms
:return: a list of full_text's from the tweets for the given query
"""
response = requests.get(API_ENDPOINT + '/get_text', params={'query': query, "username": username})
return response.json()
def get_tweets(query):
"""
function to do a twitter search for the query and get the tweets
:param query: @user or a normal search terms
:return: list of tweets
"""
response = requests.get(API_ENDPOINT + '/submit_query', params={'query': query, "username": username})
return response.json()
def get_user_lists(query):
"""
A maximum of 100 results will be returned by this call. Subscribed lists are returned first, followed by owned lists
This means that if a user owns 90 lists and subscribes to 20 lists, this method returns 90 lists and 10 subscribed
lists.
:param query: @username
:return:list of twitter lists
"""
response = requests.post(API_ENDPOINT + '/user_lists', data={'query': query, "username": username})
return response.json()
def get_user_in_lists(query):
"""
Returns the lists that the user is a member of
:param query: @username
:return: list is twitter lists
"""
response = requests.post(API_ENDPOINT + '/user_in_lists', data={'query': query, "username": username})
return response.json()
def get_user_subscribed_lists(query):
"""
Returns the lists that the user has subscribed to
:param query: @username
:return: list is twitter lists
"""
response = requests.post(API_ENDPOINT + '/user_subscribed_lists', data={'query': query, "username": username})
return response.json()
def get_list_subscribers(query):
"""
Returns the list of subscribers to a given list
:param query: username/listname
:return: list is twitter lists
"""
response = requests.post(API_ENDPOINT + '/list_subscribers', data={'query': query, "username": username})
return response.json()
def get_list(query):
"""
Returns the list of member statuses from a given twitter list
:param query: username/listname
:return: list
"""
response = requests.get(API_ENDPOINT + '/get_list', data={'query': query, "username": username})
return response.json()
if __name__ == '__main__':
print(get_list("@dorait/lists/daily"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment