#coin-counter.py# 931 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env python
  2. from flask import Flask
  3. import requests
  4. import datetime
  5. import re
  6. import json
  7. app = Flask(__name__)
  8. @app.route('/')
  9. def home():
  10. data = api()
  11. if data == error_message:
  12. return error_message
  13. text = ""
  14. for article in data:
  15. text = text + f"""
  16. <div class='{article['id']}'>
  17. <p>{article['date']}</p>
  18. <h1><a href='{article['url']}'>{article['title']}</a></h1>
  19. <img src='https://pokemon.com{article['image']}' alt='{article['alt']}'>
  20. <p>{article['shortDescription']}</p>
  21. </div>
  22. <hr>
  23. """
  24. return text
  25. @app.route('/us/pokemon-news/<url>')
  26. def article(url):
  27. data = requests.get("https://www.pokemon.com/us/pokemon-news/"+url).text
  28. with open("index.html", "w") as f:
  29. f.write(data)
  30. find = json.loads(re.findall('<script type="application/ld\+json">((.|\n)*?)</script>', data)[0][0])["articleBody"]
  31. return find
  32. if __name__ == '__main__':
  33. app.run(port=80)