Added RedditPageType enum
This commit is contained in:
parent
7999cb488f
commit
3020e015b5
@ -12,33 +12,17 @@ changelog:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import re
|
|
||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
|
from enum import Enum
|
||||||
from typing import Awaitable, Callable
|
from typing import Awaitable, Callable
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
from requests.models import Response
|
|
||||||
|
|
||||||
|
class RedditPageType(Enum):
|
||||||
def parse_reddit_page(response: Response):
|
SUBREDDIT = "r"
|
||||||
data = json.loads(response.content)
|
USER = "u"
|
||||||
output = []
|
SUBREDDIT_COMMENTS = "r"
|
||||||
if "data" not in data: return output
|
USER_COMMENTS = "u"
|
||||||
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"],
|
|
||||||
|
|
||||||
"author_username": item["author"],
|
"author_username": item["author"],
|
||||||
"author_id": item["author_fullname"],
|
"author_id": item["author_fullname"],
|
||||||
|
Loading…
Reference in New Issue
Block a user