nytimes.py 650 B

12345678910111213141516171819202122
  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. req = requests.get(url)
  9. data = json.loads(req.content)
  10. parsedData = []
  11. stockData = {}
  12. for datum in data:
  13. stockData = ['title'] = data['title']
  14. stockData = ['abstract'] = data['abstract']
  15. stockData = ['section'] = data['section']
  16. stockData = ['byline'] = data['byline']
  17. stockData = ['views'] = data['views']
  18. parsedData.append(stockData)
  19. return parsedData