예제 #1
0
def newest():
    """Returns a list of the newest articles on the nytimes.com 
    as tuples containing the title of the article and the article's url."""

    key = auth.keys()['newswire']
    base_url = 'http://api.nytimes.com/svc/news/v2/content/nyt/all/24.json'

    params = {'api-key': key}
    r = requests.get(base_url, params=params)

    if r.status_code != 200:
        r.raise_for_status()

    response = json.loads(r.text)
    return [(x['headline'], x['url']) for x in response['results']]
예제 #2
0
def most_popular():
    """Returns a list of the most popular articles on nytimes.com as
    tuples containing the title and url."""

    key = auth.keys()['popular']
    base_url = 'http://api.nytimes.com/svc/mostpopular/v2/mostviewed/all-sections/30.json'
    params = {'api-key': key}
    r = requests.get(base_url, params=params)
    

    if r.status_code != 200:
        r.raise_for_status()


    response = json.loads(r.text)    
    return [(x['title'], x['url']) for x in response['results']]
예제 #3
0
def search(query):
    """Searches for an article in the NYTimes database.

    Keyword arguments: 
    query -- the search query, in NYTimes format

    Returns a list of tuples containing article titles and article
    urls (as strings)"""
    
    key = auth.keys()['search']
    base_url = 'http://api.nytimes.com/svc/search/v1/article'
    params = {'query': query, 'api-key': key}
    r = requests.get(base_url, params=params)
    
    if r.status_code != 200:
        r.raise_for_status()

    response = json.loads(r.text)
    return [(x['title'], x['url']) for x in response['results']]
예제 #4
0
import tweepy as tw
from auth import keys

api = tw.API(keys(), wait_on_rate_limit=True)

twitter_handle = "xyluz"

#  initial request for most recent tweets (200 is the maximum allowed count)
user = api.get_user(twitter_handle)
print(user.name)
print(user.description)
print(user.location)