|
import os |
|
import requests |
|
import json |
|
from datetime import datetime, timedelta |
|
|
|
# Get domains from environment variable |
|
DOMAINS = os.getenv("DOMAINS", "") |
|
if not DOMAINS: |
|
print("No domains provided. Exiting.") |
|
exit(1) |
|
|
|
DOMAINS = [domain.strip() for domain in DOMAINS.split(",")] |
|
|
|
# Slack Webhook URL (Set this as a GitHub Secret) |
|
SLACK_WEBHOOK_URL = os.getenv("SLACK_WEBHOOK_URL") |
|
SLACK_CHANNEL_NAME = "#domain-checks" # Make sure to add your channel name, else slack API will fail |
|
|
|
def send_notification(message, channel="slack"): |
|
"""Send a notification to the desired channel (Slack, Telegram, etc.).""" |
|
if channel == "slack": |
|
send_slack_message(message) |
|
else: |
|
print(f"Unknown channel: {channel}") |
|
|
|
def send_slack_message(message): |
|
"""Send a message to Slack.""" |
|
if not SLACK_WEBHOOK_URL: |
|
print("Slack Webhook URL not configured.") |
|
return |
|
|
|
payload = { |
|
"text": message, |
|
"channel": SLACK_CHANNEL_NAME, |
|
"icon_emoji": ":squirrel:", |
|
"username": "Domain Spy" |
|
} |
|
headers = {"Content-Type": "application/json"} |
|
|
|
response = requests.post(SLACK_WEBHOOK_URL, data=json.dumps(payload), headers=headers) |
|
|
|
if response.status_code == 200: |
|
print("Slack message sent successfully.") |
|
else: |
|
print(f"Failed to send Slack message: {response.text}") |
|
|
|
def check_domain(domain): |
|
"""Check domain status via WHOIS API.""" |
|
url = f"http://api.whois.vu/?q={domain}" |
|
|
|
try: |
|
response = requests.get(url) |
|
data = response.json() |
|
|
|
print(f"Domain {domain} available? {data['available']}") |
|
|
|
|
|
# Check if domain is available |
|
if data['available'] == "yes": |
|
send_notification(f"🎯 The domain `{domain}` is available for registration! Act fast!") |
|
|
|
if "expires" in data: |
|
expiry_date = datetime.utcfromtimestamp(data["expires"]) |
|
today = datetime.utcnow() |
|
|
|
print(f"Domain {domain} expires on {expiry_date.date()}") |
|
|
|
# Check if the domain is expiring in 30 days |
|
if expiry_date == today + timedelta(days=30): |
|
send_notification(f"⚠️ The domain `{domain}` will expire in 30 days on {expiry_date.date()}. Be ready to grab it!") |
|
elif expiry_date < today: |
|
send_notification(f"❌ The domain `{domain}` has expired on {expiry_date.date()}. Check if it's available for purchase!") |
|
|
|
# Check if the domain is pending delete |
|
if "statuses" in data and "pendingDelete" in data["statuses"]: |
|
send_notification(f"🚨 The domain `{domain}` is pending deletion! Stay alert!") |
|
|
|
except Exception as e: |
|
print(f"Error checking domain {domain}: {e}") |
|
|
|
# Check all domains |
|
for domain in DOMAINS: |
|
check_domain(domain) |