mirror of
https://github.com/simon987/opendirectories-bot.git
synced 2025-12-14 23:59:02 +00:00
Initial commit
This commit is contained in:
27
reddit_bot.py
Normal file
27
reddit_bot.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import os
|
||||
|
||||
|
||||
class RedditBot:
|
||||
|
||||
def __init__(self, log_file: str):
|
||||
|
||||
self.log_file = log_file
|
||||
|
||||
if not os.path.isfile(log_file):
|
||||
self.crawled = []
|
||||
else:
|
||||
with open(log_file, "r") as f:
|
||||
self.crawled = f.read().split("\n")
|
||||
self.crawled = list(filter(None, self.crawled))
|
||||
|
||||
def log_crawl(self, post_id):
|
||||
|
||||
self.crawled.append(post_id)
|
||||
|
||||
with open(self.log_file, "w") as f:
|
||||
for post_id in self.crawled:
|
||||
f.write(post_id + "\n")
|
||||
|
||||
def has_crawled(self, post_id):
|
||||
|
||||
return post_id in self.crawled
|
||||
Reference in New Issue
Block a user