From 96b001522fb1663696570a9c051f7f4d24741cff Mon Sep 17 00:00:00 2001 From: Cromatin Date: Thu, 6 Feb 2025 18:24:22 +0100 Subject: [PATCH] Replaced praw with the asyncpraw libary --- requirements.txt | 2 +- src/platforms/reddit.py | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/requirements.txt b/requirements.txt index 847acb4..cc47caa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ discord.py==2.4.0 -praw==7.8.1 +asyncpraw==7.8.1 colorama==0.4.6 aiohttp==3.11.11 pillow==11.1.0 \ No newline at end of file diff --git a/src/platforms/reddit.py b/src/platforms/reddit.py index 0f278ce..b764fb2 100644 --- a/src/platforms/reddit.py +++ b/src/platforms/reddit.py @@ -1,13 +1,12 @@ -import praw -import praw.models +import asyncpraw +import asyncpraw.models import logging from utils.event_counter import Event_Counter from utils.datetime_tools import get_elapsed_time_milliseconds -from typing import Union from datetime import datetime -class Reddit_Adapter(praw.Reddit): - """A class that extends and abstracts the functionality of the `praw.Reddit` class by adding +class Reddit_Adapter(asyncpraw.Reddit): + """A class that extends and abstracts the functionality of the `asyncpraw.Reddit` class by adding logging and request tracking capabilities.""" VERSION = "1.0" number_of_instances = 0 @@ -25,11 +24,11 @@ class Reddit_Adapter(praw.Reddit): self.__events = Event_Counter(1000) self.__logger = logging.getLogger(f"pltfm.reddit.{self.__instance_number}") - def fetch(self, post_url:str) -> praw.models.Submission: + async def fetch(self, post_url:str) -> asyncpraw.models.Submission: """Fetches specified submission (post) and returns it""" start_time = datetime.now().timestamp() self.__events.increment() - subm = self.submission(url = post_url) + subm = await self.submission(url = post_url) self.__logger.debug(f"Submission for post (URL: {post_url}), successfully fetched after {get_elapsed_time_milliseconds(datetime.now().timestamp() - start_time)}") return subm