This repository has been archived on 2023-10-01. You can view files and clone it, but cannot push or open issues or pull requests.
PyNyaaTa/pynyaata2/__init__.py

50 lines
961 B
Python
Raw Normal View History

2023-01-04 15:57:16 +00:00
import asyncio
2023-01-01 23:44:48 +00:00
from datetime import datetime
2023-01-01 11:13:32 +00:00
2023-01-04 15:57:16 +00:00
from flask import Flask, redirect, render_template, request, url_for
2023-01-01 11:13:32 +00:00
2023-06-04 15:53:29 +00:00
from pynyaata2.bridge import search_all
from pynyaata2.translations import current_lang, i18n
2023-01-04 23:49:54 +00:00
2023-01-04 15:57:16 +00:00
2023-01-01 11:13:32 +00:00
app = Flask(__name__)
@app.context_processor
def utility_processor():
2023-01-01 23:44:48 +00:00
current_date = datetime.now()
2023-01-04 14:43:20 +00:00
apocalypse_left = (
datetime(current_date.year + 5 - (current_date.year % 5), 6, 4, 0, 1)
- current_date
)
return dict(
_=i18n,
current_lang=current_lang(),
apocalypse_left=apocalypse_left,
)
2023-01-01 11:13:32 +00:00
@app.route("/")
def index():
return render_template("index.html.j2")
@app.route("/search")
def search():
2023-01-04 15:57:16 +00:00
query = request.args.get("q")
if not query:
return redirect(url_for("index"))
torrents = asyncio.run(search_all(query))
return render_template("search.html.j2", torrents=torrents)
2023-01-01 11:13:32 +00:00
2022-12-22 00:01:21 +00:00
def run():
2023-01-01 11:13:32 +00:00
app.run("0.0.0.0")
if __name__ == "__main__":
run()