# ！/usr/bin/python3
# -*- coding: utf-8 -*-
# Copyright (c) 2017-2020 Rhilip <rhilipruan@gmail.com>

import json

from pymysql import escape_string
from flask import Blueprint, request, jsonify, redirect

from app import mysql
from .gen import Gen

getinfo_blueprint = Blueprint('infogen', __name__, url_prefix="/movieinfo")


@getinfo_blueprint.route("/gen", methods=["GET", "POST"])
def gen():
    if request.method == "POST":
        url = request.form["url"]
    elif request.method == "GET":
        url = request.args.get("url")
    else:
        url = ""

    if url:
        _gen = Gen(url=url)

        row, data = mysql.exec(
            "SELECT * FROM `api`.`gen_info` WHERE `site`='{}' AND `sid`='{}'".format(_gen.site, _gen.sid),
            r_dict=True, ret_row=True
        )

        if int(row) == 0:
            data = _gen.gen()
            if data["success"]:  # 正确获取的情况下缓存请求结果
                mysql.exec(
                    "INSERT INTO `api`.`gen_info` (`site`, `sid`, `data`)"
                    " VALUES ('{}', '{}', '{}')".format(_gen.site, _gen.sid, escape_string(json.dumps(data)))
                )
        else:
            data_str = data.get("data")
            data = json.loads(data_str)

        return jsonify(data)
    else:
        return redirect("https://git.io/vFvmP", code=301)

@@ -105,16 +105,28 @@
 ort json
+%0Aimport time
 %0A%0Afrom p
@@ -580,16 +580,41 @@
 if url:%0A
+        t0 = time.time()%0A
         
@@ -647,16 +647,19 @@
    row, 
+db_
 data = m
@@ -850,16 +850,29 @@
 w) == 0:
+  # %E6%95%B0%E6%8D%AE%E5%BA%93%E6%97%A0%E8%AF%A5%E7%BC%93%E5%AD%98%E6%95%B0%E6%8D%AE
 %0A       
@@ -1209,15 +1209,25 @@
 data
-_str = 
+ = json.loads(db_
 data
@@ -1238,21 +1238,19 @@
 (%22data%22)
-%0A    
+)%0A%0A
         
@@ -1257,32 +1257,43 @@
 data
- = json.loads(data_str)%0A
+.update(%7B%22cost%22: time.time() - t0%7D)
 %0A   

Add time cost