提交 8b9def21 编写于 作者: 梦想橡皮擦's avatar 梦想橡皮擦 💬

上线头像生成API

上级 0203d062
......@@ -35,8 +35,12 @@ from .file.index import *
from .antispider.index import *
from .csdn.index import *
from .slow.index import *
from .user.index import *
from .apis.index import *
app.register_blueprint(s)
app.register_blueprint(f)
app.register_blueprint(antispider)
app.register_blueprint(cs)
app.register_blueprint(slow)
\ No newline at end of file
app.register_blueprint(slow)
app.register_blueprint(u)
app.register_blueprint(api)
\ No newline at end of file
from flask import Blueprint, send_file
from PIL import Image, ImageDraw, ImageFont
import random
import unicodedata
import os
import io
api = Blueprint('apis', __name__, url_prefix='/api')
@api.route('/avatars')
def index():
app_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
static_path = os.path.join(app_root, 'static')
# 生成随机汉字
def get_random_common_char():
# 读取文件中的常用汉字
with open(os.path.join(static_path, 'demo.txt'), 'r', encoding='utf-8') as f:
common_chars = f.read()
# 去除空格
common_chars = common_chars.replace(' ', '')
common_chars = common_chars.strip()
# 创建字符映射表
translator = {ord(c): None for c in common_chars if unicodedata.category(c).startswith('P')}
# 使用字符映射表去除标点符号
s = common_chars.translate(translator)
return random.choice(s)
# 可以生成任意内容
han_char1 = get_random_common_char()
han_char2 = get_random_common_char()
han_char = han_char1 + han_char2
# 生成图片
image = Image.new('RGB', (64, 64), (255, 255, 255))
draw = ImageDraw.Draw(image)
font = ImageFont.truetype(os.path.join(static_path, 'font/msyh.ttf'), 28)
# 绘制一个圆形
# 正方形的中心坐标
x = 32.0
y = 32.0
# 正方形的边长
length = 62.0
# 计算半径
r = length / 2
# 计算圆的左上角和右下角的坐标
left = x - r
top = y - r
right = x + r
bottom = y + r
draw.ellipse((left, top, right, bottom), fill=(0, 129, 255))
draw.text((4, 12), han_char, font=font, fill=(255, 255, 255))
# 将图像转换成字节流
buf = io.BytesIO()
image.save(buf, format='png')
buf.seek(0)
return send_file(buf, mimetype='image/png')
......@@ -58,3 +58,5 @@ class Csdn(db.Model, EntityBase):
fensi = db.Column(db.Integer)
tie = db.Column(db.Integer)
ip = db.Column(db.String(255))
url = db.Column(db.String(255))
此差异已折叠。
......@@ -16,6 +16,7 @@
<li class="nav-item">
<a href="/index" class="nav-link {{nav['h']}}">案例场</a>
</li>
<li class="nav-item">
<a class="nav-link {{nav['b']}}" href="/blog">站点建设中</a>
</li>
......
......@@ -7,6 +7,7 @@
}
}
</style>
<div class="container">
......@@ -17,7 +18,7 @@
<strong>CSDN 2022 博客之星总排名</strong> 👉 绿色背景是总分前 200(晋级区)👈</p>
<p class="text-success p-0"><small>数据同步时间:2023-01-04 21:00</small></p>
<p class="m-0"><small>来都来了,不去给橡皮擦打个5分么?</small> <br> <a target="_blank"
href="https://bbs.csdn.net/topics/611387187"><small>https://bbs.csdn.net/topics/611387187</small></a>
href="https://bbs.csdn.net/topics/611387187"><small>https://bbs.csdn.net/topics/611387187</small></a>
</p>
</div>
......@@ -57,7 +58,13 @@
<tr>
{% endif %}
<td>{{loop.index}}</td>
<td>{{u.nickname}}</td>
<td>
{% if loop.index<=bg_green %}
<a href="{{u.url}}" target="_blank" style="color:white;">{{u.nickname}}</a>
{% else %}
<a href="{{u.url}}" target="_blank" style="color:black;">{{u.nickname}}</a>
{% endif %}
</td>
<td>{% if u.cateName =='后端' %}
<span class="badge bg-danger">{{u.cateName}}</span>
{% elif u.cateName == '前端'%}
......
......@@ -53,11 +53,8 @@
<tr>
<td>{{loop.index}}</td>
<td>{{u.nickname}}</td>
<td>
{{u.cateName}}
</td>
<td><a href="{{u.url}}" target="_blank" style="color:black;">{{u.nickname}}</a></td>
<td>{{u.cateName}}</td>
<td>{{u.totalScore}}</td>
<td>{{u.regtime}}</td>
......
......@@ -9,6 +9,7 @@
}
</style>
<div class="container">
<div class=" table-responsive">
......@@ -46,7 +47,12 @@
<tr>
{% endif %}
<td>{{loop.index}}</td>
<td>{{u.nickname}}</td>
<td> {% if loop.index<=bg_green %}
<a href="{{u.url}}" target="_blank" style="color:white;">{{u.nickname}}</a>
{% else %}
<a href="{{u.url}}" target="_blank" style="color:black;">{{u.nickname}}</a>
{% endif %}
</td>
<td>{% if u.cateName =='后端' %}
<span class="badge bg-danger">{{u.cateName}}</span>
{% elif u.cateName == '前端'%}
......
......@@ -22,7 +22,7 @@
</div>
<div class="timeline-event">
<div class="timeline-heading">
<h4>爬虫训练场 V0.0.16 发布</h4>
<h4>爬虫训练场 V0.16.0 发布</h4>
</div>
<div class="timeline-body">
<p>更新 反爬案例 --- IP 限制次数!</p>
......@@ -38,7 +38,7 @@
</div>
<div class="timeline-event">
<div class="timeline-heading">
<h4>爬虫训练场 V0.0.15 发布</h4>
<h4>爬虫训练场 V0.15.0 发布</h4>
</div>
<div class="timeline-body">
<p>token 加密案例 + 导航样式修改 + 首页样式修改 + 新增专栏购买跳转地址</p>
......@@ -54,7 +54,7 @@
</div>
<div class="timeline-event">
<div class="timeline-heading">
<h4>爬虫训练场 V0.0.12 发布</h4>
<h4>爬虫训练场 V0.12.0 发布</h4>
</div>
<div class="timeline-body">
<p>案例正常更新,维护 CSDN 总榜数据</p>
......@@ -70,7 +70,7 @@
</div>
<div class="timeline-event">
<div class="timeline-heading">
<h4>爬虫训练场 V0.0.11 发布</h4>
<h4>爬虫训练场 V0.11.0 发布</h4>
</div>
<div class="timeline-body">
<p>案例正常更新</p>
......@@ -136,7 +136,7 @@
<h4>上线第一个反爬案例,基于 UserAgent 的反爬实践。 </h4>
</div>
<div class="timeline-body">
<p>反爬案例开始更新!爬虫训练场 V0.0.4</p>
<p>反爬案例开始更新!爬虫训练场 V0.4.0</p>
</div>
<div class="timeline-footer">
<p class="text-right">2022年12月28日 21:59</p>
......@@ -166,7 +166,7 @@
</div>
<div class="timeline-event">
<div class="timeline-heading">
<h4>爬虫训练场上线 V0.0.1 版本</h4>
<h4>爬虫训练场上线 V0.1.0 版本</h4>
</div>
<div class="timeline-body">
<p>愿景:让天下没有失效的爬虫</p>
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<img src="{{url_for('apis.index')}}" alt="">
</body>
</html>
\ No newline at end of file
from flask import Blueprint, jsonify, request
from flask import render_template
u = Blueprint('user', __name__, url_prefix='/u')
@u.route('/i')
def index():
return render_template('user/index.html')
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册