pokemon-news-json.py 900 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env python
  2. # Script for Pokemon News RSS in rssguard
  3. # Post processing using this API:
  4. # https://www.pokemon.com/api/1/us/news/get-news.json
  5. import re
  6. import json
  7. from datetime import datetime
  8. import requests
  9. URL = "https://www.pokemon.com/api/1/us/news/get-news.json"
  10. json_data = json.loads(requests.get(URL).text)
  11. items = []
  12. for rel in json_data:
  13. id = rel["url"]
  14. url = rel["url"]
  15. title = rel["alt"]
  16. date = datetime.strptime(rel["date"], "%B %d, %Y").isoformat()
  17. image = rel["image"]
  18. html = f"""
  19. <img src='https://www.pokemon.com{image}'>
  20. <p>{rel['shortDescription']}</p>
  21. """
  22. item = {
  23. "author": {"name": "Pokemon Company"},
  24. "title": title,
  25. "id": id,
  26. "content_html": html,
  27. "url": f"https://pokemon.com{url}",
  28. "date_published": date
  29. }
  30. items.append(item)
  31. json_feed = {
  32. "title": "Pokemon News",
  33. "items": items,
  34. }
  35. print(json.dumps(json_feed))