关于我
我是一名专注于RPA(机器人流程自动化)和Python全栈开发的程序员。日常工作包括设计和实现自动化流程,开发Web应用,以及解决各种业务场景中的效率问题。
我相信代码的力量可以极大地提升工作效率,将人们从重复枯燥的任务中解放出来。除了工作,我也喜欢研究新技术,折腾各种开发工具
技术栈
以下是我主要使用的技术和工具:
RPA开发
影刀RPA
88%
pandas
81%
自动化脚本
85%
Web开发
Python/Flask
70%
HTML/CSS/JS
55%
数据库设计
62%
其他技能
API开发
87%
Web抓取
52%
Git版本控制
42%
web开发 · Flask示例代码
# app.py - FlaskAPI
from flask import Flask, request, jsonify
from flask_sqlalchemy import SQLAlchemy
from flask_jwt_extended import JWTManager, create_access_token, jwt_required, get_jwt_identity
from datetime import timedelta
import os
# 初始化Flask应用
app = Flask(__name__)
# 配置数据库
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///blog.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['JWT_SECRET_KEY'] = 'your-secret-key-here'
app.config['JWT_ACCESS_TOKEN_EXPIRES'] = timedelta(hours=1)
# 初始化扩展
db = SQLAlchemy(app)
jwt = JWTManager(app)
# 定义数据模型
class User(db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True, nullable=False)
email = db.Column(db.String(120), unique=True, nullable=False)
password = db.Column(db.String(200), nullable=False)
posts = db.relationship('Post', backref='author', lazy=True)
class Post(db.Model):
__tablename__ = 'posts'
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(200), nullable=False)
content = db.Column(db.Text, nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
# 用户注册接口
@app.route('/api/register', methods=['POST'])
def register():
data = request.get_json()
# 验证输入
if not data or not data.get('username') or not data.get('email') or not data.get('password'):
return jsonify({'error': 'Missing required fields'}), 400
# 检查用户是否已存在
if User.query.filter_by(username=data['username']).first():
return jsonify({'error': 'Username already exists'}), 400
# 创建新用户(实际应用中密码需要加密)
user = User(
username=data['username'],
email=data['email'],
password=data['password'] # 应该使用hash
)
db.session.add(user)
db.session.commit()
return jsonify({'message': 'User created successfully', 'user_id': user.id}), 201
# 用户登录接口
@app.route('/api/login', methods=['POST'])
def login():
data = request.get_json()
# 查找用户
user = User.query.filter_by(username=data.get('username')).first()
# 验证密码(实际应用中需要比对hash)
if not user or user.password != data.get('password'):
return jsonify({'error': 'Invalid username or password'}), 401
# 生成JWT令牌
access_token = create_access_token(identity=user.id)
return jsonify({'access_token': access_token, 'user_id': user.id}), 200
# 创建文章接口(需要认证)
@app.route('/api/posts', methods=['POST'])
@jwt_required()
def create_post():
data = request.get_json()
user_id = get_jwt_identity()
if not data or not data.get('title') or not data.get('content'):
return jsonify({'error': 'Title and content are required'}), 400
post = Post(
title=data['title'],
content=data['content'],
user_id=user_id
)
db.session.add(post)
db.session.commit()
return jsonify({'message': 'Post created successfully', 'post_id': post.id}), 201
# 获取所有文章
@app.route('/api/posts', methods=['GET'])
def get_posts():
page = request.args.get('page', 1, type=int)
per_page = request.args.get('per_page', 10, type=int)
posts = Post.query.order_by(Post.created_at.desc()).paginate(page=page, per_page=per_page)
return jsonify({
'posts': [{
'id': p.id,
'title': p.title,
'content': p.content,
'author': p.author.username,
'created_at': p.created_at.isoformat()
} for p in posts.items],
'total': posts.total,
'page': page,
'pages': posts.pages
}), 200
# 获取单篇文章
@app.route('/api/posts/<int:post_id>', methods=['GET'])
def get_post(post_id):
post = Post.query.get_or_404(post_id)
return jsonify({
'id': post.id,
'title': post.title,
'content': post.content,
'author': post.author.username,
'created_at': post.created_at.isoformat()
}), 200
# 更新文章(需要认证)
@app.route('/api/posts/<int:post_id>', methods=['PUT'])
@jwt_required()
def update_post(post_id):
post = Post.query.get_or_404(post_id)
user_id = get_jwt_identity()
# 检查权限
if post.user_id != user_id:
return jsonify({'error': 'You can only edit your own posts'}), 403
data = request.get_json()
if 'title' in data:
post.title = data['title']
if 'content' in data:
post.content = data['content']
db.session.commit()
return jsonify({'message': 'Post updated successfully'}), 200
# 删除文章(需要认证)
@app.route('/api/posts/<int:post_id>', methods=['DELETE'])
@jwt_required()
def delete_post(post_id):
post = Post.query.get_or_404(post_id)
user_id = get_jwt_identity()
# 检查权限
if post.user_id != user_id:
return jsonify({'error': 'You can only delete your own posts'}), 403
db.session.delete(post)
db.session.commit()
return jsonify({'message': 'Post deleted successfully'}), 200
# 健康检查接口
@app.route('/api/health', methods=['GET'])
def health_check():
return jsonify({'status': 'healthy', 'timestamp': datetime.utcnow().isoformat()}), 200
# 错误处理
@app.errorhandler(404)
def not_found(error):
return jsonify({'error': 'Resource not found'}), 404
@app.errorhandler(500)
def internal_error(error):
db.session.rollback()
return jsonify({'error': 'Internal server error'}), 500
# 启动应用
if __name__ == '__main__':
with app.app_context():
db.create_all() # 创建数据库表
app.run(debug=True, host='0.0.0.0', port=5000)
terminal -- 秋雨祎的工作环境
$ whoami
> 秋雨祎 - RPA开发者 & Python
$ cat skills.txt
> 影刀RPA · Python · Flask · 自动化 · 数据抓取 · API开发
$ find ./projects -name "*.rpa"
> 找到 12 个RPA自动化项目
$ echo "自动化让生活更美好!"
联系我
如果您有RPA自动化需求、Python项目合作机会,或者只是想聊聊技术,欢迎通过以下方式联系我:
# 联系方式
contact_info = {
"WeChat-ID": du2394713824,
"QQ": "3239295856",
"Email": "3239295856@qq.com",
"Blog": "https://blog.csdn.net/2402_86120691?spm=1010.2135.3001.5343",
"Location": "中国 · 义乌"
}