yt-community.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env python
  2. # This is broken lol
  3. # Script for Generating RSS from YT community tab
  4. # Example URL: https://www.youtube.com/@PaPaSea/community
  5. import re
  6. import json
  7. from datetime import datetime
  8. from bs4 import BeautifulSoup
  9. import requests
  10. import sys
  11. #sys.stdin.reconfigure(encoding="utf-8")
  12. #
  13. #input_data = sys.stdin.read()
  14. HEADERS = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20121201 icecat/17.0.1', "Content-Type": "text/html;charset=UTF-8"}
  15. data = requests.get("https://www.pokemon.com/us/pokemon-news", headers=HEADERS).text
  16. #soup = BeautifulSoup(input_data, "html.parser")
  17. soup = BeautifulSoup(data, "html.parser")
  18. name = json.loads(soup.find_all("script")[-6].text.split("var ytInitialData = ")[1].split(";")[-2])
  19. #print(json.dumps(name))
  20. posts = name["contents"]["twoColumnBrowseResultsRenderer"]["tabs"][5]["tabRenderer"]["content"]["sectionListRenderer"]["contents"][0]["itemSectionRenderer"]["contents"]
  21. for post in posts:
  22. post = post["backstagePostThreadRenderer"]["post"]["backstagePostRenderer"]["contentText"]
  23. items = []
  24. json_feed = {
  25. "title": "Youtube Community",
  26. "items": items,
  27. }
  28. print(json.dumps(json_feed))