This repository has been archived on 2026-08-27. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
RequestCounter/app/utils/response.py
T

79 lines
2.9 KiB
Python
Raw Permalink Normal View History

2022-02-18 19:30:54 +08:00
#!/usr/bin/env python3
# -- coding:utf-8 --
# @Author: markushammered@gmail.com
# @Development Tool: PyCharm
2022-03-26 08:02:25 +08:00
# @Create Time: 2022/3/25
2022-04-15 20:47:05 +08:00
# @File Name: response.py
2022-02-18 19:30:54 +08:00
2022-03-26 08:02:25 +08:00
from ..db.db import SQLite as db
2022-03-26 08:03:39 +08:00
from flask import request
2022-02-18 19:30:54 +08:00
from flask import render_template
2022-03-26 08:02:25 +08:00
from typing import Tuple
2022-02-18 19:30:54 +08:00
2022-04-15 20:47:05 +08:00
def index_(theme: str, length: int, name: str, count: str) -> str or Tuple[bool, str]:
2022-02-18 19:30:54 +08:00
"""
渲染模板
2022-03-26 08:02:25 +08:00
:param theme:
:param length:
:param name:
:param count:
2022-02-18 19:30:54 +08:00
:return:
"""
2022-03-26 08:02:25 +08:00
datas = db().fetching_table(theme)
2022-02-18 19:30:54 +08:00
context = []
for i in count:
if i == '0':
context.append({'url': datas[0]['url'],
'width': datas[0]['width'],
'height': datas[0]['height']})
elif i == '1':
context.append({'url': datas[1]['url'],
'width': datas[1]['width'],
'height': datas[1]['height']})
elif i == '2':
context.append({'url': datas[2]['url'],
'width': datas[2]['width'],
'height': datas[2]['height']})
elif i == '3':
context.append({'url': datas[3]['url'],
'width': datas[3]['width'],
'height': datas[3]['height']})
elif i == '4':
context.append({'url': datas[4]['url'],
'width': datas[4]['width'],
'height': datas[4]['height']})
elif i == '5':
context.append({'url': datas[5]['url'],
'width': datas[5]['width'],
'height': datas[5]['height']})
elif i == '6':
context.append({'url': datas[6]['url'],
'width': datas[6]['width'],
'height': datas[6]['height']})
elif i == '7':
context.append({'url': datas[7]['url'],
'width': datas[7]['width'],
'height': datas[7]['height']})
elif i == '8':
context.append({'url': datas[8]['url'],
'width': datas[8]['width'],
'height': datas[8]['height']})
elif i == '9':
context.append({'url': datas[9]['url'],
'width': datas[9]['width'],
'height': datas[9]['height']})
2022-02-18 19:30:54 +08:00
for p, i in zip(context, range(0, length)):
2022-02-25 18:29:02 +08:00
p['position'] = i * p['width'] # 设置每张图片对应的位置
2022-02-18 19:30:54 +08:00
general_width = datas[0]['width'] * length # 计算出图片总长度
general_height = datas[0]['height'] # 总宽度
2022-02-18 19:30:54 +08:00
return render_template('view.html',
2022-03-26 08:02:25 +08:00
context=context,
title=name,
2022-03-26 08:03:39 +08:00
address=request.remote_addr,
2022-03-26 08:02:25 +08:00
general_height=general_height,
general_width=general_width)