Back to flask server + async
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
26900df6fa
commit
a769f7fddf
@ -1,9 +1,8 @@
|
|||||||
import logging
|
from asyncio import get_event_loop, set_event_loop, SelectorEventLoop
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from operator import attrgetter, itemgetter
|
from operator import attrgetter, itemgetter
|
||||||
|
|
||||||
from flask import redirect, render_template, request, url_for, abort
|
from flask import redirect, render_template, request, url_for, abort
|
||||||
from gevent.pywsgi import WSGIServer
|
|
||||||
|
|
||||||
from . import utils
|
from . import utils
|
||||||
from .config import app, auth, ADMIN_USERNAME, ADMIN_PASSWORD, MYSQL_ENABLED, APP_PORT, IS_DEBUG
|
from .config import app, auth, ADMIN_USERNAME, ADMIN_PASSWORD, MYSQL_ENABLED, APP_PORT, IS_DEBUG
|
||||||
@ -52,10 +51,14 @@ def colorify(model):
|
|||||||
return get_instance(model.link, model.title.keyword).color
|
return get_instance(model.link, model.title.keyword).color
|
||||||
|
|
||||||
|
|
||||||
|
@app.context_processor
|
||||||
|
def inject_user():
|
||||||
|
return dict(mysql_disabled=not MYSQL_ENABLED)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def home():
|
def home():
|
||||||
return render_template('layout.html', search_form=SearchForm(), title='Animes torrents search engine',
|
return render_template('layout.html', search_form=SearchForm(), title='Animes torrents search engine')
|
||||||
mysql_disabled=not MYSQL_ENABLED)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/search')
|
@app.route('/search')
|
||||||
@ -64,14 +67,16 @@ def search():
|
|||||||
if not query:
|
if not query:
|
||||||
return redirect(url_for('home'))
|
return redirect(url_for('home'))
|
||||||
|
|
||||||
return render_template('search.html', search_form=SearchForm(), connectors=run_all(query),
|
set_event_loop(SelectorEventLoop())
|
||||||
mysql_disabled=not MYSQL_ENABLED)
|
return render_template('search.html', search_form=SearchForm(),
|
||||||
|
connectors=get_event_loop().run_until_complete(run_all(query)))
|
||||||
|
|
||||||
|
|
||||||
@app.route('/latest')
|
@app.route('/latest')
|
||||||
@app.route('/latest/<int:page>')
|
@app.route('/latest/<int:page>')
|
||||||
def latest(page=1):
|
def latest(page=1):
|
||||||
torrents = run_all('', return_type=ConnectorReturn.HISTORY, page=page)
|
set_event_loop(SelectorEventLoop())
|
||||||
|
torrents = get_event_loop().run_until_complete(run_all('', return_type=ConnectorReturn.HISTORY, page=page))
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
for torrent in torrents:
|
for torrent in torrents:
|
||||||
@ -80,8 +85,7 @@ def latest(page=1):
|
|||||||
result['self'] = get_instance(result['href'], '')
|
result['self'] = get_instance(result['href'], '')
|
||||||
results.sort(key=itemgetter('date'), reverse=True)
|
results.sort(key=itemgetter('date'), reverse=True)
|
||||||
|
|
||||||
return render_template('latest.html', search_form=SearchForm(), torrents=results, page=page,
|
return render_template('latest.html', search_form=SearchForm(), torrents=results, page=page)
|
||||||
mysql_disabled=not MYSQL_ENABLED)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/list')
|
@app.route('/list')
|
||||||
@ -188,6 +192,4 @@ def admin_edit(link_id=None):
|
|||||||
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
logging.basicConfig(level=logging.DEBUG if IS_DEBUG else logging.INFO)
|
app.run('0.0.0.0', APP_PORT, IS_DEBUG)
|
||||||
http_server = WSGIServer(('', APP_PORT), app)
|
|
||||||
http_server.serve_forever()
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from asyncio import gather
|
||||||
|
|
||||||
from .animeultime import AnimeUltime
|
from .animeultime import AnimeUltime
|
||||||
from .core import Other
|
from .core import Other
|
||||||
from .nyaa import Nyaa
|
from .nyaa import Nyaa
|
||||||
@ -5,14 +7,12 @@ from .pantsu import Pantsu
|
|||||||
from .yggtorrent import YggTorrent, YggAnimation
|
from .yggtorrent import YggTorrent, YggAnimation
|
||||||
|
|
||||||
|
|
||||||
def run_all(*args, **kwargs):
|
async def run_all(*args, **kwargs):
|
||||||
return [
|
return list(await gather(Nyaa(*args, **kwargs).run(),
|
||||||
Nyaa(*args, **kwargs).run(),
|
Pantsu(*args, **kwargs).run(),
|
||||||
Pantsu(*args, **kwargs).run(),
|
YggTorrent(*args, **kwargs).run(),
|
||||||
YggTorrent(*args, **kwargs).run(),
|
YggAnimation(*args, **kwargs).run(),
|
||||||
YggAnimation(*args, **kwargs).run(),
|
AnimeUltime(*args, **kwargs).run()))
|
||||||
AnimeUltime(*args, **kwargs).run(),
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def get_instance(url, query):
|
def get_instance(url, query):
|
||||||
|
@ -191,7 +191,7 @@ class ConnectorCore(ABC):
|
|||||||
else:
|
else:
|
||||||
return ConnectorLang.JP
|
return ConnectorLang.JP
|
||||||
|
|
||||||
def run(self):
|
async def run(self):
|
||||||
if self.on_error:
|
if self.on_error:
|
||||||
if self.return_type is ConnectorReturn.SEARCH:
|
if self.return_type is ConnectorReturn.SEARCH:
|
||||||
self.search()
|
self.search()
|
||||||
|
@ -11,4 +11,3 @@ cloudscraper==1.2.50
|
|||||||
Js2Py==0.70
|
Js2Py==0.70
|
||||||
polling2==0.4.6
|
polling2==0.4.6
|
||||||
dateparser==1.0.0
|
dateparser==1.0.0
|
||||||
gevent==20.12.1
|
|
||||||
|
Reference in New Issue
Block a user