Replaced praw with the asyncpraw libary

This commit is contained in:
2025-02-06 18:24:22 +01:00
parent 3a9608d863
commit 96b001522f
2 changed files with 7 additions and 8 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
discord.py==2.4.0 discord.py==2.4.0
praw==7.8.1 asyncpraw==7.8.1
colorama==0.4.6 colorama==0.4.6
aiohttp==3.11.11 aiohttp==3.11.11
pillow==11.1.0 pillow==11.1.0
+6 -7
View File
@@ -1,13 +1,12 @@
import praw import asyncpraw
import praw.models import asyncpraw.models
import logging import logging
from utils.event_counter import Event_Counter from utils.event_counter import Event_Counter
from utils.datetime_tools import get_elapsed_time_milliseconds from utils.datetime_tools import get_elapsed_time_milliseconds
from typing import Union
from datetime import datetime from datetime import datetime
class Reddit_Adapter(praw.Reddit): class Reddit_Adapter(asyncpraw.Reddit):
"""A class that extends and abstracts the functionality of the `praw.Reddit` class by adding """A class that extends and abstracts the functionality of the `asyncpraw.Reddit` class by adding
logging and request tracking capabilities.""" logging and request tracking capabilities."""
VERSION = "1.0" VERSION = "1.0"
number_of_instances = 0 number_of_instances = 0
@@ -25,11 +24,11 @@ class Reddit_Adapter(praw.Reddit):
self.__events = Event_Counter(1000) self.__events = Event_Counter(1000)
self.__logger = logging.getLogger(f"pltfm.reddit.{self.__instance_number}") 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""" """Fetches specified submission (post) and returns it"""
start_time = datetime.now().timestamp() start_time = datetime.now().timestamp()
self.__events.increment() 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)}") self.__logger.debug(f"Submission for post (URL: {post_url}), successfully fetched after {get_elapsed_time_milliseconds(datetime.now().timestamp() - start_time)}")
return subm return subm