Files
MinecraftUpdates/test_setup.py
T

119 lines
3.2 KiB
Python
Raw Permalink Normal View History

2026-03-11 23:24:42 +00:00
"""
Test script to verify bot setup before running
"""
import sys
import config
from minecraft_checker import get_latest_releases, parse_release_date
def check_config():
"""Verify configuration is filled in."""
print("[TEST] Checking configuration...")
required = [
"REDDIT_CLIENT_ID",
"REDDIT_CLIENT_SECRET",
"REDDIT_USERNAME",
"REDDIT_PASSWORD",
"SUBREDDIT"
]
missing = []
for key in required:
value = getattr(config, key, None)
if not value or value.startswith("YOUR_"):
missing.append(key)
else:
print(f"{key}: configured")
if missing:
print(f"\n✗ Missing configuration:")
for key in missing:
print(f" - {key}")
return False
return True
def check_minecraft_api():
"""Test fetching from Minecraft API."""
print("\n[TEST] Checking Minecraft API...")
try:
latest = get_latest_releases()
if not latest:
print(" ✗ Failed to fetch latest releases")
return False
print(f" ✓ Connected to Minecraft launcher manifest")
for version in latest:
release_date = parse_release_date(version["releaseTime"])
print(f" - {version['id']} ({version['type']}) - {release_date}")
return True
except Exception as e:
print(f" ✗ Error: {e}")
return False
def check_reddit_connection():
"""Test Reddit API connection."""
print("\n[TEST] Checking Reddit connection...")
try:
import praw
except ImportError:
print(" ✗ praw not installed. Run: pip install -r requirements.txt")
return False
try:
reddit = praw.Reddit(
client_id=config.REDDIT_CLIENT_ID,
client_secret=config.REDDIT_CLIENT_SECRET,
user_agent=config.REDDIT_USER_AGENT,
username=config.REDDIT_USERNAME,
password=config.REDDIT_PASSWORD
)
user = reddit.user.me()
print(f" ✓ Connected as u/{user.name}")
# Check if we can access the subreddit
subreddit = reddit.subreddit(config.SUBREDDIT)
print(f" ✓ Can access r/{config.SUBREDDIT} (subscribers: {subreddit.subscribers:,})")
# Check if we can post
try:
subreddit.mod.modqueue()
print(f" ✓ Have moderator access to r/{config.SUBREDDIT}")
except:
print(f" ⚠ No moderator access (must be able to post normally)")
return True
except Exception as e:
print(f" ✗ Reddit connection failed: {e}")
return False
def main():
print("=" * 50)
print("Minecraft Update Bot - Setup Test")
print("=" * 50)
config_ok = check_config()
api_ok = check_minecraft_api()
reddit_ok = check_reddit_connection()
print("\n" + "=" * 50)
if config_ok and api_ok and reddit_ok:
print("✓ All checks passed! Ready to run: python main.py")
return 0
else:
print("✗ Some checks failed. See above for details.")
return 1
if __name__ == "__main__":
sys.exit(main())