Moved Reddit test code into it's dedicated file

This commit is contained in:
Nathan Windisch 2024-07-24 22:44:49 +01:00
parent 194ee6272d
commit 4bcc5ab62c
2 changed files with 5 additions and 19 deletions

View File

@ -197,19 +197,4 @@ class Tools:
await __event_emitter__({ "data": { "description": f"Starting retrieval for {page_type.value}/{id}...", "status": "in_progress", "done": False }, "type": "status" })
page = RedditPage(id, page_type).get_page()
await __event_emitter__({ "data": { "description": f"Retrieved {len(page.posts)} posts and {len(page.comments)} comments from {page_type.value}/{id}.", "status": "complete", "done": True }, "type": "status" })
return str(page)
async def main():
__user__ = {
"valves": Tools.UserValves(
USER_AGENT="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36"
)
}
async def mock_event_emitter(event: dict): print("Event Emitted:", event["data"])
await Tools().get_reddit_feed("sysadmin", RedditPageType.SUBREDDIT, mock_event_emitter, __user__)
await Tools().get_reddit_feed("sysadmin/1eb73j6", RedditPageType.SUBREDDIT_COMMENTS, mock_event_emitter, __user__)
await Tools().get_reddit_feed("natfan", RedditPageType.USER, mock_event_emitter, __user__)
import asyncio
if __name__ == "__main__": asyncio.run(main())
return str(page)

View File

@ -2,7 +2,7 @@
import sys, os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../src")))
# Unfortunately, we don't get any type hinting, but this does work :)
from reddit import Tools
from reddit import RedditPageType, Tools
async def main():
__user__ = {
@ -11,8 +11,9 @@ async def main():
)
}
async def mock_event_emitter(event: dict): print("Event Emitted:", event["data"])
await Tools().get_subreddit_feed("sysadmin", mock_event_emitter, __user__)
await Tools().get_user_feed("NathanWindisch", mock_event_emitter, __user__)
await Tools().get_reddit_feed("sysadmin", RedditPageType.SUBREDDIT, mock_event_emitter, __user__)
await Tools().get_reddit_feed("sysadmin/1eb73j6", RedditPageType.SUBREDDIT_COMMENTS, mock_event_emitter, __user__)
await Tools().get_reddit_feed("natfan", RedditPageType.USER, mock_event_emitter, __user__)
import asyncio
if __name__ == "__main__": asyncio.run(main())