helixring/main.py

36 lines
No EOL
1.1 KiB
Python

from flask import Flask, redirect, url_for
app = Flask(__name__)
domains = [ # replace with your webring domains
"example.net",
"example.com",
"example.org"
]
port = 42069 # replace with your desired port
@app.route('/')
def index():
"""Display the list of domains"""
return '\n'.join(f'<a href="https://{d}">{d}</a>' for d in domains)
@app.route('/next/<domain>')
def next_domain(domain):
"""Automatically redirect to the next domain in the ring"""
if domain not in domains:
return 'Doesn\'t exist!', 451
current_idx = domains.index(domain)
next_idx = (current_idx + 1) % len(domains)
return redirect('https://' + domains[next_idx], code=302)
@app.route('/back/<domain>')
def back_domain(domain):
"""Automatically redirect to the previous domain in the ring"""
if domain not in domains:
return 'Doesn\'t exist!', 451
current_idx = domains.index(domain)
prev_idx = (current_idx - 1) % len(domains)
return redirect('https://' + domains[prev_idx], code=302)
if __name__ == '__main__':
app.run(debug=False, port=port)