diff --git a/src/reddit.py b/src/reddit.py index 465c0b9..10e3a52 100644 --- a/src/reddit.py +++ b/src/reddit.py @@ -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"],