Prevent unneeded updates
This commit is contained in:
@@ -14,6 +14,7 @@ import config
|
|||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
|
|
||||||
class DatabaseManager:
|
class DatabaseManager:
|
||||||
|
|
||||||
def __init__(self, db_name="christmas_event.db"):
|
def __init__(self, db_name="christmas_event.db"):
|
||||||
self.conn = sqlite3.connect(db_name, check_same_thread=False)
|
self.conn = sqlite3.connect(db_name, check_same_thread=False)
|
||||||
self.cursor = self.conn.cursor()
|
self.cursor = self.conn.cursor()
|
||||||
@@ -164,6 +165,10 @@ class SafetyFilter:
|
|||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
|
|
||||||
class ChristmasBot:
|
class ChristmasBot:
|
||||||
|
|
||||||
|
# Store the last updated data to prevent unneeded updates.
|
||||||
|
last_updated_data = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
print("🎄 Initializing Christmas Helper...")
|
print("🎄 Initializing Christmas Helper...")
|
||||||
self.reddit = praw.Reddit(
|
self.reddit = praw.Reddit(
|
||||||
@@ -211,6 +216,11 @@ class ChristmasBot:
|
|||||||
print("📝 Updating Forest Dashboard...")
|
print("📝 Updating Forest Dashboard...")
|
||||||
data = self.db.get_forest_data()
|
data = self.db.get_forest_data()
|
||||||
|
|
||||||
|
if self.last_updated_data and self.last_updated_data == data:
|
||||||
|
# Nothing changed.
|
||||||
|
print(f"No change in dashboard, last checked {now}...", end="\r")
|
||||||
|
return
|
||||||
|
|
||||||
body = "# 🎄 The Christmas Forest 🎄\n\n"
|
body = "# 🎄 The Christmas Forest 🎄\n\n"
|
||||||
body += "### How to Participate:\n"
|
body += "### How to Participate:\n"
|
||||||
body += "1. Send a DM to u/{}\n".format(config.username)
|
body += "1. Send a DM to u/{}\n".format(config.username)
|
||||||
|
|||||||
Reference in New Issue
Block a user