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