Added RedditPageType enum

This commit is contained in:
Nathan Windisch 2024-07-24 22:36:26 +01:00
parent 7999cb488f
commit 3020e015b5

View File

@ -12,33 +12,17 @@ changelog:
"""
import re
import json
import requests
from enum import Enum
from typing import Awaitable, Callable
from pydantic import BaseModel, Field
from requests.models import Response
def parse_reddit_page(response: Response):
data = json.loads(response.content)
output = []
if "data" not in data: return output
if "children" not in data["data"]: return output
for item in data["data"]["children"]: output.append(item)
return output
def parse_posts(data: list):
posts = []
for item in data:
if item["kind"] != "t3": continue # skip non-post items
item = item["data"]
posts.append({
"id": item["name"],
"title": item["title"],
"description": item["selftext"],
"link": item["url"],
class RedditPageType(Enum):
SUBREDDIT = "r"
USER = "u"
SUBREDDIT_COMMENTS = "r"
USER_COMMENTS = "u"
"author_username": item["author"],
"author_id": item["author_fullname"],