|
|
@ -7,7 +7,9 @@ from flask_sqlalchemy import SQLAlchemy |
|
|
|
from flask_limiter import Limiter |
|
|
|
from flask_limiter.util import get_remote_address |
|
|
|
from mastodon import Mastodon |
|
|
|
from apscheduler.schedulers.background import BackgroundScheduler |
|
|
|
import random |
|
|
|
import atexit |
|
|
|
from config import C |
|
|
|
WRONG_ANS_HTML = '''<html> |
|
|
|
<head> |
|
|
@ -97,13 +99,26 @@ def choose_new_next(min_like_num=10): |
|
|
|
last_paragraph_id = story.tail |
|
|
|
next_one = Paragraph.query.filter_by(parent_id=last_paragraph_id, is_hidden=False)\ |
|
|
|
.order_by(Paragraph.like_num.desc()).first() |
|
|
|
print(next_one) |
|
|
|
if next_one and next_one.like_num >= min_like_num: |
|
|
|
print(next_one, next_one.like_num) |
|
|
|
|
|
|
|
story.text += next_one.text |
|
|
|
story.total_like_num += next_one.like_num |
|
|
|
story.tail = next_one.id |
|
|
|
next_one.is_chosen = True |
|
|
|
|
|
|
|
db.session.commit() |
|
|
|
# 更新 story! |
|
|
|
db.session.commit() |
|
|
|
|
|
|
|
scheduler = BackgroundScheduler() |
|
|
|
for d in range(5, 15): |
|
|
|
for m in range(0, 24 * 60, C.period): |
|
|
|
scheduler.add_job(func=choose_new_next, trigger='date', run_date=datetime(2021, 11, d, m // 60, m % 60), args=[1] if C.debug else []) |
|
|
|
scheduler.start() |
|
|
|
|
|
|
|
# Shut down the scheduler when exiting the app |
|
|
|
atexit.register(lambda: scheduler.shutdown()) |
|
|
|
|
|
|
|
|
|
|
|
def sample_question(qs, n=3): |
|
|
@ -198,6 +213,7 @@ def story(story_id): |
|
|
|
cs_login_url = MAST_LOGIN_URL |
|
|
|
guest_login_url = url_for('main_bp.guest_login') |
|
|
|
verify_questions = sample_question(C.verify_questions) |
|
|
|
period = C.period |
|
|
|
|
|
|
|
return render_template('story.html', **locals()) |
|
|
|
|
|
|
@ -226,7 +242,7 @@ def create(): |
|
|
|
|
|
|
|
@bp.route('/react', methods=['POST']) |
|
|
|
@login_required |
|
|
|
@limiter.limit("4 / minute") |
|
|
|
@limiter.limit("40 / minute") |
|
|
|
def react(): |
|
|
|
kind = request.form.get('kind', type=int) |
|
|
|
pid = request.form.get('pid', type=int) |
|
|
|