nytimes.py 664 B

1234567891011121314151617181920212223
  1. '''module containing a handful of methods for aggregating
  2. data from the NY Times.'''
  3. import requests
  4. import json
  5. def fetcharticle(apikey, url):
  6. '''returns the JSON data of the most
  7. popular articles by view from the past 24 hours.'''
  8. parameters = {'api-key' : apikey}
  9. req = requests.get(url, params=parameters)
  10. data = json.loads(req.content)
  11. parsedData = []
  12. for datum in data['results']:
  13. newData = {
  14. "title": datum["title"],
  15. "abstract": datum["abstract"],
  16. "section": datum["section"],
  17. "byline": datum["byline"],
  18. }
  19. parsedData.append(newData)
  20. return parsedData