mirror of
https://github.com/simon987/od-database.git
synced 2025-12-13 23:09:01 +00:00
Minimal configuration for reddit comment callback
This commit is contained in:
27
callbacks.py
27
callbacks.py
@@ -1,6 +1,7 @@
|
||||
from tasks import Task
|
||||
from crawl_server.reddit_bot import RedditBot
|
||||
from tasks import Task, TaskResult
|
||||
from reddit_bot import RedditBot
|
||||
import praw
|
||||
from search.search import SearchEngine
|
||||
|
||||
|
||||
class PostCrawlCallback:
|
||||
@@ -8,7 +9,7 @@ class PostCrawlCallback:
|
||||
def __init__(self, task: Task):
|
||||
self.task = task
|
||||
|
||||
def run(self):
|
||||
def run(self, task_result: TaskResult, search: SearchEngine):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@@ -36,26 +37,30 @@ class RedditCallback(PostCrawlCallback):
|
||||
user_agent='github.com/simon987/od-database (by /u/Hexahedr_n)')
|
||||
self.reddit_bot = RedditBot("crawled.txt", reddit)
|
||||
|
||||
def run(self):
|
||||
def run(self, task_result: TaskResult, search: SearchEngine):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class RedditPostCallback(RedditCallback):
|
||||
|
||||
def run(self):
|
||||
def run(self, task_result: TaskResult, search: SearchEngine):
|
||||
print("Reddit post callback for task " + str(self.task))
|
||||
pass
|
||||
|
||||
|
||||
class RedditCommentCallback(RedditCallback):
|
||||
|
||||
def run(self):
|
||||
print("Reddit comment callback for task " + str(self.task))
|
||||
pass
|
||||
def run(self, task_result: TaskResult, search: SearchEngine):
|
||||
|
||||
comment_id = self.task.callback_args["comment_id"]
|
||||
print("Replying to comment " + comment_id)
|
||||
|
||||
stats = search.get_stats(self.task.website_id)
|
||||
message = self.reddit_bot.get_comment(stats, self.task.website_id)
|
||||
print(message)
|
||||
self.reddit_bot.reply(self.reddit_bot.reddit.comment(comment_id), message)
|
||||
|
||||
|
||||
class DiscordCallback(PostCrawlCallback):
|
||||
|
||||
def run(self):
|
||||
def run(self, task_result: TaskResult, search: SearchEngine):
|
||||
print("Discord callback for task " + str(self.task))
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user