DomainExpiration/app.py

34 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

from flask import Flask, render_template, request, redirect, url_for
import whois
app = Flask(__name__)
# In-memory list to store domain info. In production, you’d use a database.
domains = []
@app.route('/')
def home():
return render_template('home.html', domains=domains)
@app.route('/add', methods=['GET', 'POST'])
def add_domain():
if request.method == 'POST':
# Get a list of domains from the form (one or multiple)
domain_list = request.form.getlist('domain')
for domain in domain_list:
if domain.strip(): # ignore empty strings
try:
w = whois.whois(domain)
# Some WHOIS responses return a list of dates.
exp_date = w.expiration_date
if isinstance(exp_date, list):
exp_date = exp_date[0]
except Exception as e:
exp_date = f"Error: {e}"
domains.append({'domain': domain, 'expiration_date': exp_date})
return redirect(url_for('home'))
return render_template('add_domain.html')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5050, debug=True)