├── README.md ├── app ├── __init__.py ├── api │ ├── __init__.py │ ├── api说明.md │ ├── articles.py │ ├── authentication.py │ ├── comments.py │ ├── errors.py │ ├── ficitons.py │ └── users.py ├── fiction │ ├── __init__.py │ └── views.py ├── main │ ├── __init__.py │ ├── errors.py │ ├── forms.py │ └── views.py ├── models.py ├── mylogger.py ├── static │ ├── css │ │ ├── dashboard.css │ │ ├── github-markdown.css │ │ ├── ie10-viewport-bug-workaround.css │ │ ├── mycss.css │ │ └── xscss.css │ └── js │ │ └── ie-emulation-modes-warning.js ├── templates │ ├── add_task.html │ ├── article.html │ ├── base.html │ ├── base_login.html │ ├── fiction.html │ ├── fiction_error.html │ ├── fiction_index.html │ ├── fiction_lst.html │ ├── index.html │ ├── login.html │ ├── login_in.html │ ├── login_up.html │ ├── manage_article.html │ ├── manage_task.html │ ├── tools.html │ └── wrarticle.html ├── tools.py └── xiaoshuo │ ├── __init__.py │ ├── config.py │ ├── data │ └── log │ │ ├── error_20180418.log │ │ └── info_20180418.log │ ├── mylogger.py │ ├── spider_tools.py │ └── xiaoshuoSpider.py ├── blog.sql ├── config.py ├── manage.py ├── requirements.txt ├── sendemail.py ├── start.sh ├── stop.sh └── wsgi.py /README.md: -------------------------------------------------------------------------------- 1 | # 基于flask+requests个人博客系统 2 | 3 | [博客地址](http://47.96.119.139) 4 | 5 | ## 1.基本环境搭建 6 | 7 | ```python 8 | 1.本人使用的系统是 Centos7 9 | 2.python环境 10 | 2.1 安装python3.6 11 | 2.2 安装pip工具 12 | 3.安装mysql数据库 使用的是mysql 5.7 charset=utf8 13 | 4.建立相关数据库及表 14 | ``` 15 | 16 | ## 2.安装教程(推荐安装环境:Centos7,python版本要超过3.4) 17 | 18 | 1.git clone https://github.com/longzx-9527/flask_spider.git 19 | 2.cd flask_spider 20 | 3.pyvenv myvenv #虚拟环境 21 | 4.source venv/bin/activate #激活虚拟环境 22 | 5.pip install -r requirement.txt # 安装依赖 23 | 24 | 以上,应该安装好了python依赖包。 25 | 接下来是初始化数据: 26 | 27 | 1.首先你应该创建了一个blog数据库(utf-8格式),然后修改config.py里面的user、passwd、db 28 | 2.初始化数据库:python manage.py db init 29 | 3.生成数据库语句:python manage.py db migrate 30 | 4.创建数据库:python manage.py upgrade 31 | 32 | 运行:`./start.sh` 33 | 34 | ## 2.个人博客首页 35 | 36 | ### 2.1 首页界面 37 | 38 | ![首页](https://images2018.cnblogs.com/blog/1339195/201804/1339195-20180421191246312-1031301812.png) 39 | 40 | ![首页](https://images2018.cnblogs.com/blog/1339195/201804/1339195-20180421191428100-352502656.png) 41 | 42 | ### 2.2 可以发布一些自己写的文章 43 | 44 | ![写文章](https://images2018.cnblogs.com/blog/1339195/201804/1339195-20180420101341637-1481677605.png) 45 | 46 | ### 2.3 文章显示 47 | 48 | ![文章显示](https://images2018.cnblogs.com/blog/1339195/201804/1339195-20180421191528180-222376656.png) 49 | 50 | ### 2.4 文章管理 51 | 52 | ![文章显示](https://images2018.cnblogs.com/blog/1339195/201804/1339195-20180421191718709-1351293168.png) 53 | 54 | ## 3.小说爬取展示 55 | 56 | ### 最终实现效果如下图: 57 | 58 | #### 首页显示 59 | 60 | ![首页显示](https://images2018.cnblogs.com/blog/1339195/201804/1339195-20180418232426530-100667854.png) 61 | 62 | 可以输入查询小说,如果小说不存在,就调用后台爬虫程序下载 63 | 64 | ![章节列表](https://images2018.cnblogs.com/blog/1339195/201804/1339195-20180418232908530-1212209202.png) 65 | 66 | 点开具体页面显示,小说章节列表,对于每个章节,如果本地没有就直接下载,可以点开具体章节开心的阅读,而没有广告,是的没有广告,纯净的 67 | 68 | ![章节内容](https://images2018.cnblogs.com/blog/1339195/201804/1339195-20180418233105974-334389035.png) 69 | -------------------------------------------------------------------------------- /app/__init__.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | from flask_bootstrap import Bootstrap 3 | from flask_sqlalchemy import SQLAlchemy 4 | from flask_login import LoginManager 5 | from config import config 6 | 7 | bootstrap = Bootstrap() 8 | db = SQLAlchemy() 9 | login_manager = LoginManager() 10 | # 会话保护等级 11 | login_manager.session_protection = 'strong' 12 | # 设置登录页面端点 13 | login_manager.login_view = 'main.login_in' 14 | 15 | 16 | def create_app(config_name): 17 | # __name__ 决定应用根目录 18 | app = Flask(__name__) 19 | # 初始化app配置 20 | app.config.from_object(config[config_name]) 21 | config[config_name].init_app(app) 22 | # 扩展应用初始化 23 | bootstrap.init_app(app) 24 | db.init_app(app) 25 | login_manager.init_app(app) 26 | 27 | #初始化蓝本 28 | from .main import main as main_blueprint 29 | app.register_blueprint(main_blueprint) 30 | from .fiction import fiction as fiction_blueprint 31 | app.register_blueprint(fiction_blueprint) 32 | #初始化api 33 | from .api import api 34 | api.init_app(app) 35 | from .api import auth_api as authapi_blueprint 36 | app.register_blueprint(authapi_blueprint) 37 | 38 | return app 39 | -------------------------------------------------------------------------------- /app/api/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Author: longzx 3 | # @Date: 2018-04-22 20:08:25 4 | # @cnblog:http://www.cnblogs.com/lonelyhiker/ 5 | 6 | from flask import Blueprint 7 | from flask_restful import Api 8 | 9 | api = Api() 10 | auth_api = Blueprint(name='auth_api', import_name=__name__) 11 | from . import authentication 12 | 13 | # 文章路由 14 | from .articles import Articles, ArticleList 15 | 16 | api.add_resource(Articles, "/api/articles", endpoint="get_articles") 17 | api.add_resource( 18 | Articles, "/api/articles/", endpoint="get_article") 19 | 20 | api.add_resource(ArticleList, "/api/articlelist") 21 | api.add_resource( 22 | ArticleList, "/api/articlelist/", endpoint="articleList") 23 | 24 | # 用户路由 25 | from .users import Users, UserList 26 | api.add_resource(Users, "/api/users/") 27 | api.add_resource(UserList, "/api/users") 28 | 29 | # 评论路由 30 | from .comments import Comments, Commentsupport, Commentoppose 31 | 32 | api.add_resource(Comments, "/api/comments/") 33 | api.add_resource(Commentsupport, "/api/commentsp/") 34 | api.add_resource(Commentoppose, "/api/commentop/") 35 | -------------------------------------------------------------------------------- /app/api/api说明.md: -------------------------------------------------------------------------------- 1 | # flask_spider的API说明 2 | 3 | ## 1.基于Token的认证及实现 4 | 5 | 整体思路: 6 | 1.用户使用用户名密码验证成功,返回token 7 | 2.以后就是用token作为这个用户的通行证 8 | 9 | ## 1.1 修改modes.py 10 | 11 | ```python 12 | 13 | from itsdangerous import TimedJSONWebSignatureSerializer as Serializer 14 | 15 | class User(UserMixin, db.Model): 16 | # ... 17 | 18 | def generate_auth_token(self, expiration=3600): 19 | s = Serializer(current_app.config['SECRET_KEY'], expries_in=expiration) 20 | return s.dumps({'user_id': self.user_id}).decode('utf-8') 21 | 22 | @staticmethod 23 | def verify_auth_token(token): 24 | s = Serializer(current_app.config['SECRET_KEY']) 25 | try: 26 | data = s.loads(token) 27 | except expression as identifier: 28 | return None 29 | return User.query.get(data['user_id']) 30 | 31 | ``` 32 | 33 | ## 1.2.authentication.py 34 | 35 | 验证客户信息: 36 | 1.实现verify_password回调函数去验证用户名和密码,验证通过返回True,否则返回False。 37 | 2.Flask-HTTPAuth再调用这个回调函数。 38 | 39 | ```python 40 | 41 | from flask import g, jsonify 42 | from flask_httpauth import HTTPBasicAuth 43 | 44 | from . import auth_api 45 | from ..models import User 46 | 47 | auth = HTTPBasicAuth() 48 | 49 | 50 | @auth_api.route('/api/resource') 51 | @auth.login_required 52 | def get_resource(): 53 | return jsonify({'data': 'Hello, %s!' % g.user.user_name}) 54 | 55 | 56 | @auth_api.route('/api/token') 57 | @auth.login_required 58 | def get_auth_token(): 59 | token = g.user.generate_auth_token() 60 | return jsonify({'token': token}) 61 | 62 | 63 | @auth.verify_password 64 | def verify_password(username_or_token, password): 65 | # first try to authenticate by token 66 | user = User.verify_auth_token(username_or_token) 67 | if not user: 68 | # try to authenticate with username/password 69 | user = User.query.filter_by(user_name=username_or_token).first() 70 | if not user or not user.verify_password(password): 71 | return False 72 | g.user = user 73 | return True 74 | 75 | ``` 76 | 77 | ## 1.3 测试 78 | 79 | ```python 80 | # 1.获取所有客户信息 81 | $>curl -i -X GET http://127.0.0.1:5000/api/users 82 | HTTP/1.0 401 UNAUTHORIZED 83 | Content-Type: text/html; charset=utf-8 84 | Content-Length: 19 85 | WWW-Authenticate: Basic realm="Authentication Required" 86 | Server: Werkzeug/0.14.1 Python/3.6.1 87 | Date: Wed, 02 May 2018 11:01:25 GMT 88 | #提示需要认证 89 | 90 | # 2.使用curl测试请求获取一个认证token 91 | $>curl -u test:1234 -i -X GET http://127.0.0.1:5000/api/token 92 | HTTP/1.0 200 OK 93 | Content-Type: application/json 94 | Content-Length: 169 95 | Server: Werkzeug/0.14.1 Python/3.6.1 96 | Date: Wed, 02 May 2018 11:16:34 GMT 97 | 98 | { 99 | "token": "eyJhbGciOiJIUzI1NiIsImlhdCI6MTUyNTI1OTc5NCwiZXhwIjoxNTI1MjYzMzk0fQ.eyJ1c2VyX2lkIjoiMjAxODA1MDIwMDAwMDAwMyJ9.4gS1ISMTw2yNH9ywCX8DWdHAR1BBMxB1QTdvlooDhNA" 100 | } 101 | 102 | # 3.使用token一访问受保护的API 103 | $>curl -u eyJhbGciOiJIUzI1NiIsImlhdCI6MTUyNTI1ODMwOSwiZXhwIjoxNTI1MjYxOTA5fQ.eyJ1c2VyX2lkIjoiMjAxODA1MDIwMDAwMDAwMyJ9.JHDl4Ti8Ev_H9JMbHRnH8Le3PXfEh_5PGmMl3pAWNwQ:unused -i -X GET http://127.0.0.1:5000/api/users 104 | 105 | [ { 106 | "user_id": "2018042100000002", 107 | "user_name": "Nicolas Cage", 108 | "nickname": null, 109 | "sex": null, 110 | "age": null, 111 | "email": "Nicolas Cage@163.com", 112 | "last_login_tm": null, 113 | "user_crt_dt": null, 114 | "attention_cnt": 0 115 | }, 116 | { 117 | "user_id": "2018050200000003", 118 | "user_name": "test", 119 | "nickname": "test", 120 | "sex": null, 121 | "age": null, 122 | "email": "123@qq.com", 123 | "last_login_tm": null, 124 | "user_crt_dt": null, 125 | "attention_cnt": 0 126 | } 127 | ] 128 | #请求里面带了unused字段。只是为了标识而已,替代密码的占位符。 129 | 130 | ``` 131 | -------------------------------------------------------------------------------- /app/api/articles.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Author: longzx 3 | # @Date: 2018-04-24 18:03:29 4 | # @cnblog:http://www.cnblogs.com/lonelyhiker/ 5 | import re 6 | import markdown 7 | from time import strftime 8 | from flask_restful import Resource, reqparse, fields, marshal_with 9 | from ..models import Article 10 | from ..models import db 11 | from ..tools import generate_id 12 | 13 | post_parser = reqparse.RequestParser() 14 | 15 | post_parser.add_argument( 16 | 'article_title', type=str, required=True, help="article_title is required") 17 | post_parser.add_argument('article_content', type=str, required=True) 18 | post_parser.add_argument('f_type', type=str) 19 | post_parser.add_argument('article_url', type=str) 20 | 21 | # 格式化输出 22 | resource_full_fields = { 23 | 'article_id': fields.String, 24 | 'article_title': fields.String, 25 | 'article_text': fields.String, 26 | 'article_summary': fields.String, 27 | 'article_read_cnt': fields.Integer, 28 | 'article_sc': fields.Integer, 29 | 'article_pl': fields.Integer, 30 | 'article_date': fields.DateTime, 31 | 'article_url': fields.String, 32 | 'article_type': fields.String, 33 | 'article_author': fields.String, 34 | 'user_id': fields.String 35 | } 36 | 37 | 38 | class Articles(Resource): 39 | @marshal_with(resource_full_fields) 40 | def get(self, article_id=None): 41 | if article_id: 42 | article = Article().query.filter_by(article_id=article_id).first() 43 | if article: 44 | return article 45 | else: 46 | return {"code": 200, "message": "article no exists"} 47 | else: 48 | return {"code": 404, "message": "article_id is none"} 49 | 50 | def post(self): 51 | post_args = post_parser.parse_args() 52 | article_title = post_args.get('article_title') 53 | artitle_type = post_args.get('f_type') 54 | article_text = post_args.get('article_content') 55 | article_url = post_args.get('article_url') 56 | article_text = markdown.markdown(article_text, ['extra', 'codehilite']) 57 | article_id = generate_id('article') 58 | article_date = strftime('%Y-%m-%d %H:%M:%S') 59 | article_type = '技术杂谈' if artitle_type == '1' else '人生感悟' 60 | content = re.compile('.*?>(.*?)<').findall(article_text) 61 | article_summary = '' 62 | for x in content: 63 | if x: 64 | article_summary = article_summary + x 65 | if len(article_summary) > 250: 66 | break 67 | 68 | print('article_title=', article_title) 69 | print('article_type=', article_type) 70 | print('article_date=', article_date) 71 | article_summary = "".join(article_summary.split()) 72 | print('article_summary=', article_summary) 73 | article = Article( 74 | article_id=article_id, 75 | article_title=article_title, 76 | article_type=article_type, 77 | article_text=article_text, 78 | article_summary=article_summary[:180], 79 | article_url=article_url, 80 | article_date=article_date, 81 | user_id=current_user.user_id, 82 | article_author=current_user.user_name) 83 | db.session.add(article) 84 | db.session.commit() 85 | print('add article finished') 86 | articles = Article().query.limit(8) 87 | return articles 88 | 89 | def delete(self, article_id=None): 90 | if article_id: 91 | article = Article().query.filter_by(article_id=article_id).first() 92 | db.session.delete(article) 93 | db.session.commit() 94 | return {"code": 200, "message": "delete success"} 95 | else: 96 | return {"code": 301, "message": "article_id error "} 97 | 98 | 99 | class ArticleList(Resource): 100 | @marshal_with 101 | def get(self, user_id): 102 | if user_id: 103 | articles = Article().query.filter_by(user_id=user_id).all() 104 | else: 105 | articles = Article().query.order_by(article_id).all() 106 | return articles 107 | -------------------------------------------------------------------------------- /app/api/authentication.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Author: longzx 3 | # @Date: 2018-04-22 20:20:55 4 | # @cnblog:http://www.cnblogs.com/lonelyhiker/ 5 | 6 | from flask import g, jsonify 7 | from flask_httpauth import HTTPBasicAuth 8 | 9 | from . import auth_api 10 | from ..models import User 11 | 12 | auth = HTTPBasicAuth() 13 | 14 | 15 | @auth_api.route('/api/resource') 16 | @auth.login_required 17 | def get_resource(): 18 | return jsonify({'data': 'Hello, %s!' % g.user.user_name}) 19 | 20 | 21 | @auth_api.route('/api/token') 22 | @auth.login_required 23 | def get_auth_token(): 24 | token = g.user.generate_auth_token() 25 | return jsonify({'token': token}) 26 | 27 | 28 | @auth.verify_password 29 | def verify_password(username_or_token, password): 30 | # first try to authenticate by token 31 | user = User.verify_auth_token(username_or_token) 32 | if not user: 33 | # try to authenticate with username/password 34 | user = User.query.filter_by(user_name=username_or_token).first() 35 | if not user or not user.verify_password(password): 36 | return False 37 | g.user = user 38 | return True 39 | -------------------------------------------------------------------------------- /app/api/comments.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Author: longzx 3 | # @Date: 2018-05-02 17:08:45 4 | # @cnblog:http://www.cnblogs.com/lonelyhiker/ 5 | 6 | from flask import jsonify 7 | from flask_restful import Resource, fields, reqparse, marshal_with 8 | from ..models import Comment 9 | 10 | comment_resource = { 11 | "comment_id": fields.String, 12 | "comment_text": fields.String, 13 | "comment_date": fields.DateTime, 14 | "comment_name": fields.String, 15 | "comment_support": fields.Integer, 16 | "comment_oppose": fields.Integer, 17 | "article_id": fields.String 18 | } 19 | 20 | 21 | class Comments(Resource): 22 | @marshal_with(comment_resource) 23 | def get(self, article_id=None): 24 | comments = Comment().query.filter_by(article_id=article_id).all() 25 | return comments 26 | 27 | def post(self, article_id=None): 28 | comment_name = request.form.get("name") 29 | commentary = request.form.get("commentary") 30 | commentary = markdown.markdown(commentary, ['extra', 'codehilite']) 31 | comment_id = generate_id('comment') 32 | comment_date = strftime('%Y-%m-%d %H:%M:%S') 33 | print('comment:', commentary) 34 | comment = Comment( 35 | comment_id=comment_id, 36 | comment_text=commentary, 37 | comment_date=comment_date, 38 | comment_name=comment_name, 39 | article_id=article_id) 40 | db.session.add(comment) 41 | db.session.commit() 42 | return jsonfiy({"status": "200", "message": "add success"}) 43 | 44 | 45 | class Commentsupport(Resource): 46 | @marshal_with(comment_resource) 47 | def put(self, comment_id=None): 48 | comment = Comment().query.filter_by(comment_id=comment_id).first() 49 | comment.comment_support += 1 50 | db.session.add(comment) 51 | db.session.commit() 52 | return comment 53 | 54 | 55 | class Commentoppose(Resource): 56 | @marshal_with(comment_resource) 57 | def put(self, comment_id=None): 58 | comment = Comment().query.filter_by(comment_id=comment_id).first() 59 | comment.comment_oppose += 1 60 | db.session.add(comment) 61 | db.session.commit() 62 | return comment 63 | -------------------------------------------------------------------------------- /app/api/errors.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longzx-9527/flask_spider/9a255ea83341437a94710097021564ca580c6ed6/app/api/errors.py -------------------------------------------------------------------------------- /app/api/ficitons.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Author: longzx 3 | # @Date: 2018-04-24 18:03:29 4 | # @cnblog:http://www.cnblogs.com/lonelyhiker/ 5 | 6 | from flask_restful import Resource, reqparse 7 | from flask import Request 8 | from ..models import Fiction, Fiction_Content, Fiction_Lst 9 | from ..models import db 10 | 11 | post_parser = reqparse.RequestParser() 12 | 13 | post_parser.add_argument( 14 | 'user_name', type=str, required=True, help="user_name is required") 15 | post_parser.add_argument('nickname', type=str, required=True) 16 | post_parser.add_argument('sex', type=str) 17 | post_parser.add_argument('age', type=int) 18 | post_parser.add_argument('password', type=str) 19 | post_parser.add_argument('email', type=str, required=True) 20 | 21 | 22 | class Users(Resource): 23 | print('user resource init') 24 | 25 | def get(self, user_id=None): 26 | pass 27 | 28 | def post(self): 29 | post_args = post_parser.parse_args() 30 | user = User.query.filter_by(user_name=post_args['user_name']).first() 31 | if user: 32 | return jsonify({"status": 0, "msg": "此用户已存在!!"}) 33 | user = User( 34 | user_name=post_args['user_name'], 35 | nickname=post_args['nickname'], 36 | sex=post_args['sex'], 37 | password=post_args['password'], 38 | email=post_args['email']) 39 | db.session.add(user) 40 | db.session.commit() 41 | return jsonify() 42 | 43 | def put(self): 44 | pass 45 | -------------------------------------------------------------------------------- /app/api/users.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Author: longzx 3 | # @Date: 2018-04-24 18:03:29 4 | # @cnblog:http://www.cnblogs.com/lonelyhiker/ 5 | from flask import jsonify 6 | from flask_restful import Resource, fields, marshal_with, reqparse 7 | 8 | from ..models import User, db 9 | from ..tools import generate_id 10 | from .authentication import auth 11 | """ 12 | parser = reqparse.RequestParser() 13 | parser.add_argument(*args,**kwargs) 14 | args = parser.parse_args() 15 | args是获取传来值组成的字典 16 | 17 | add_argument参数说明 18 | type:传入要转换成的类型(int,str,float) 19 | require:默认false,设置为True这个值必输 20 | action:append获取多个值,如http://localhost/?name=1&name=2 21 | dest:给传入参数key重命名 22 | location:参数位置,从Request.json/Request.args/Request.form/Request.values,headers,user_agent 23 | 单个位置:location='args' 24 | 多个位置: location= ['args','form'] 25 | 26 | 继承解析 27 | parser_copy = parser.copy() 28 | 29 | """ 30 | 31 | post_parser = reqparse.RequestParser() 32 | 33 | post_parser.add_argument( 34 | 'user_name', type=str, required=True, help="user_name is required") 35 | post_parser.add_argument('nickname', type=str, required=True) 36 | post_parser.add_argument('sex', type=str) 37 | post_parser.add_argument('age', type=int) 38 | post_parser.add_argument('password', type=str) 39 | post_parser.add_argument('email', type=str, required=True) 40 | 41 | resource_users = { 42 | 'user_id': fields.String, 43 | 'user_name': fields.String, 44 | 'nickname': fields.String, 45 | 'sex': fields.String, 46 | 'age': fields.String, 47 | 'email': fields.String, 48 | 'last_login_tm': fields.DateTime, 49 | 'user_crt_dt': fields.DateTime, 50 | 'attention_cnt': fields.Integer 51 | } 52 | 53 | 54 | class Users(Resource): 55 | @marshal_with(resource_users) 56 | def get(self, user_id=None): 57 | user = User().query.filter_by(user_id=user_id).first() 58 | return user 59 | 60 | def delete(self, user_id=None): 61 | user = User().query.filter_by(user_id=user_id).first() 62 | if user is not None: 63 | db.session.delete(user) 64 | db.session.commit() 65 | return jsonify({"status": 200, "message": "delete success"}) 66 | else: 67 | return jsonify({ 68 | "status": 404, 69 | "message": "user_id is not exists delete fail" 70 | }) 71 | 72 | 73 | class UserList(Resource): 74 | @auth.login_required 75 | @marshal_with(resource_users) 76 | def get(self): 77 | users = User().query.all() 78 | return users 79 | 80 | def post(self): 81 | post_args = post_parser.parse_args() 82 | print("user_name:", post_args.get("user_name")) 83 | user = User.query.filter_by(user_name=post_args['user_name']).first() 84 | if user: 85 | return jsonify({"status": 200, "message": "此用户已存在!!"}) 86 | else: 87 | user = User( 88 | user_name=post_args['user_name'], 89 | nickname=post_args['nickname'], 90 | sex=post_args['sex'], 91 | password=post_args['password'], 92 | email=post_args['email']) 93 | user.user_id = generate_id('user') 94 | db.session.add(user) 95 | db.session.commit() 96 | print('add user success') 97 | return jsonify({"status": 200, "message": "success"}) 98 | -------------------------------------------------------------------------------- /app/fiction/__init__.py: -------------------------------------------------------------------------------- 1 | from flask import Blueprint 2 | 3 | fiction = Blueprint(name='fiction', import_name=__name__) 4 | 5 | from . import views 6 | -------------------------------------------------------------------------------- /app/fiction/views.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Author: longzx 3 | # @Date: 2018-03-20 20:45:37 4 | # @cnblog:http://www.cnblogs.com/lonelyhiker/ 5 | 6 | import requests 7 | from bs4 import BeautifulSoup 8 | from flask import redirect, render_template, request, url_for 9 | 10 | from app import db 11 | from app.models import Fiction, Fiction_Content, Fiction_Lst 12 | from app.xiaoshuo.spider_tools import get_one_page 13 | from app.xiaoshuo.xiaoshuoSpider import (down_fiction_content, 14 | down_fiction_lst, update_fiction_lst) 15 | 16 | from . import fiction 17 | 18 | 19 | @fiction.route('/book/') 20 | def book_index(): 21 | fictions = Fiction().query.all() 22 | print(fictions) 23 | return render_template('fiction_index.html', fictions=fictions, flag=4) 24 | 25 | 26 | @fiction.route('/book/list/') 27 | def book_lst(f_id): 28 | # 1.获取全部小说 29 | fictions = Fiction().query.all() 30 | 31 | for fiction in fictions: 32 | if fiction.fiction_id == f_id: 33 | break 34 | print(fiction) 35 | # 2.获取小说章节列表 36 | fiction_lst = Fiction_Lst().query.filter_by(fiction_id=f_id).all() 37 | if len(fiction_lst) == 0: 38 | print(fiction.fiction_name) 39 | down_fiction_lst(fiction.fiction_name) 40 | fiction_lst = Fiction_Lst().query.filter_by(fiction_id=f_id).all() 41 | if len(fiction_lst) == 0: 42 | return render_template( 43 | 'fiction_error.html', message='暂无此章节信息,请重新刷新下') 44 | 45 | fiction_name = fiction_lst[0].fiction_name 46 | return render_template( 47 | 'fiction_lst.html', 48 | fictions=fictions, 49 | fiction=fiction, 50 | fiction_lst=fiction_lst, 51 | fiction_name=fiction_name, 52 | flag=4) 53 | 54 | 55 | @fiction.route('/book/fiction/') 56 | def fiction_content(): 57 | fic_id = request.args.get('id') 58 | f_url = request.args.get('f_url') 59 | print('获取书本 id={} url={}'.format(fic_id, f_url)) 60 | 61 | # 获取上一章和下一章信息 62 | fiction_lst = Fiction_Lst().query.filter_by( 63 | fiction_id=fic_id, fiction_lst_url=f_url).first() 64 | id = fiction_lst.id 65 | fiction_name = fiction_lst.fiction_lst_name 66 | pre_id = id - 1 67 | next_id = id + 1 68 | fiction_pre = Fiction_Lst().query.filter_by( 69 | id=pre_id).first().fiction_lst_url 70 | 71 | fn = Fiction_Lst().query.filter_by(id=next_id).first() 72 | if fn is None: 73 | fiction_next = None 74 | else: 75 | fiction_next = fn.fiction_lst_url 76 | f_id = fic_id 77 | # 获取具体章节内容 78 | fiction_contents = Fiction_Content().query.filter_by( 79 | fiction_id=fic_id, fiction_url=f_url).first() 80 | if fiction_contents is None: 81 | print('fiction_real_url={}'.format(fiction_lst.fiction_real_url)) 82 | 83 | down_fiction_content(fiction_lst.fiction_real_url) 84 | print('fiction_id={} fiction_url={}'.format(fic_id, f_url)) 85 | fiction_contents = Fiction_Content().query.filter_by( 86 | fiction_id=fic_id, fiction_url=f_url).first() 87 | if fiction_contents is None: 88 | return render_template('fiction_error.html', message='暂无此章节信息,请重新刷新下') 89 | print('fiction_contents=', fiction_contents) 90 | fiction_content = fiction_contents.fiction_content 91 | print('sdfewf') 92 | return render_template( 93 | 'fiction.html', 94 | f_id=f_id, 95 | fiction_name=fiction_name, 96 | fiction_pre=fiction_pre, 97 | fiction_next=fiction_next, 98 | fiction_content=fiction_content, 99 | flag=4) 100 | 101 | 102 | @fiction.route('/book/search/') 103 | def f_search(): 104 | f_name = request.args.get('f_name') 105 | print('收到输入:', f_name) 106 | # 1.查询数据库存在记录 107 | fictions = Fiction().query.all() 108 | fiction = None 109 | for x in fictions: 110 | if f_name in x.fiction_name: 111 | fiction = x 112 | break 113 | 114 | if fiction: 115 | fiction_lst = Fiction_Lst().query.filter_by( 116 | fiction_id=fiction.fiction_id).all() 117 | if len(fiction_lst) == 0: 118 | down_fiction_lst(f_name) 119 | fictions = Fiction().query.all() 120 | print('fictions=', fictions) 121 | for fiction in fictions: 122 | if f_name in fiction.fiction_name: 123 | break 124 | 125 | if f_name not in fiction.fiction_name: 126 | return render_template('fiction_error.html', message='暂无此小说信息') 127 | 128 | fiction_lst = Fiction_Lst().query.filter_by( 129 | fiction_id=fiction.fiction_id).all() 130 | return render_template( 131 | 'fiction_lst.html', 132 | fictions=fictions, 133 | fiction=fiction, 134 | fiction_lst=fiction_lst, 135 | fiction_name=fiction.fiction_name, 136 | flag=4) 137 | else: 138 | fiction_name = fiction_lst[0].fiction_name 139 | return render_template( 140 | 'fiction_lst.html', 141 | fictions=fictions, 142 | fiction=fiction, 143 | fiction_lst=fiction_lst, 144 | fiction_name=fiction_name, 145 | flag=4) 146 | else: 147 | down_fiction_lst(f_name) 148 | fictions = Fiction().query.all() 149 | print('fictions=', fictions) 150 | for fiction in fictions: 151 | if f_name in fiction.fiction_name: 152 | break 153 | 154 | if f_name not in fiction.fiction_name: 155 | return render_template('fiction_error.html', message='暂无此小说信息') 156 | 157 | fiction_lst = Fiction_Lst().query.filter_by( 158 | fiction_id=fiction.fiction_id).all() 159 | return render_template( 160 | 'fiction_lst.html', 161 | fictions=fictions, 162 | fiction=fiction, 163 | fiction_lst=fiction_lst, 164 | fiction_name=fiction.fiction_name, 165 | flag=4) 166 | 167 | 168 | @fiction.route('/update/fiction/') 169 | def update_fiction(): 170 | f_url = request.args.get('f_url') 171 | f_name = request.args.get('f_name') 172 | update_fiction_lst(f_name=f_name, f_url=f_url) 173 | print('更新列表完毕!!!!') 174 | return redirect(url_for('fiction.book_lst', f_id=f_url.split('/')[-2])) 175 | -------------------------------------------------------------------------------- /app/main/__init__.py: -------------------------------------------------------------------------------- 1 | from flask import Blueprint 2 | 3 | # 实例化蓝本对象,必须指定name蓝本名字,import_name蓝本所在包或模块 4 | main = Blueprint(name='main', import_name=__name__) 5 | 6 | # 在这个位置导入是为了防止循环导入依赖问题 7 | from . import views, errors 8 | -------------------------------------------------------------------------------- /app/main/errors.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longzx-9527/flask_spider/9a255ea83341437a94710097021564ca580c6ed6/app/main/errors.py -------------------------------------------------------------------------------- /app/main/forms.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Author: longzx 3 | # @Date: 2018-04-10 18:02:22 4 | 5 | from flask_wtf import FlaskForm 6 | from wtforms import StringField, BooleanField, PasswordField, TextField, DateField, FloatField, SubmitField 7 | from wtforms.validators import DataRequired, Length, email 8 | """ 9 | 字段类型 说  明 10 | StringField 文本字段 11 | TextAreaField 多行文本字段 12 | PasswordField 密码文本字段 13 | HiddenField 隐藏文本字段 14 | DateField 文本字段,值为 datetime.date 格式 15 | DateTimeField 文本字段,值为 datetime.datetime 格式 16 | IntegerField 文本字段,值为整数 17 | DecimalField 文本字段,值为 decimal.Decimal 18 | FloatField 文本字段,值为浮点数 19 | BooleanField 复选框,值为 True 和 False 20 | RadioField 一组单选框 21 | SelectField 下拉列表 22 | SelectMultipleField 下拉列表,可选择多个值 23 | FileField 文件上传字段 24 | SubmitField 表单提交按钮 25 | FormField 把表单作为字段嵌入另一个表单 26 | FieldList 一组指定类型的字段 27 | 28 | 验证函数 说  明 29 | Email 验证电子邮件地址 30 | EqualTo 比较两个字段的值;常用于要求输入两次密码进行确认的情况 31 | IPAddress 验证 IPv4 网络地址 32 | Length 验证输入字符串的长度 33 | NumberRange 验证输入的值在数字范围内 34 | Optional 无输入值时跳过其他验证函数 35 | Required 确保字段中有数据 36 | Regexp 使用正则表达式验证输入值 37 | URL 验证 URL 38 | AnyOf 确保输入值在可选值列表中 39 | NoneOf 确保输入值不在可选值列表中 40 | """ 41 | 42 | 43 | class LoginForm(FlaskForm): 44 | username = StringField( 45 | label='用户昵称', 46 | validators=[ 47 | DataRequired("昵称必填"), 48 | Length(min=6, max=20, message="用户名必须介于6-20个字符") 49 | ], 50 | render_kw={"placeholder": "用户名必须介于6-20个字符"}) 51 | password = PasswordField( 52 | label="用户密码", 53 | validators=[DataRequired("密码必填!")], 54 | render_kw={ 55 | "placeholder": '密码必须大于6个字符', 56 | }) 57 | 58 | remember_me = BooleanField(label='remember_me', default=False) 59 | submit = SubmitField(label='登录') 60 | 61 | 62 | class RegisterForm(FlaskForm): 63 | username = StringField( 64 | label='用户昵称', 65 | validators=[ 66 | DataRequired("昵称必填"), 67 | Length(min=6, max=20, message="用户名必须介于6-20个字符") 68 | ], 69 | render_kw={"placeholder": "用户名必须介于6-20个字符"}) 70 | password = PasswordField( 71 | label="用户密码", 72 | validators=[DataRequired("密码必填!")], 73 | render_kw={ 74 | "placeholder": '密码必须大于6个字符', 75 | }) 76 | password2 = PasswordField( 77 | label="用户密码", 78 | validators=[DataRequired("密码必填!")], 79 | render_kw={ 80 | "placeholder": '再次输入', 81 | }) 82 | email = StringField( 83 | '邮箱', 84 | validators=[email(message="邮箱格式不正确!")], 85 | render_kw={"placeholder": "E-mail: yourname@example.com"}) 86 | birthdate = DateField( 87 | label='日期', 88 | validators=[DataRequired('日期格式不正确')], 89 | render_kw={"placeholder": "日期如:2018-01-01"}) 90 | submit = SubmitField(label='注册') 91 | -------------------------------------------------------------------------------- /app/main/views.py: -------------------------------------------------------------------------------- 1 | import re 2 | import markdown 3 | import requests 4 | from datetime import datetime, timedelta 5 | from flask import (current_app, make_response, redirect, render_template, 6 | request, url_for, flash) 7 | from flask_login import login_required, current_user, login_user, logout_user 8 | 9 | from . import main 10 | from ..models import User, Article, Comment, Task, db 11 | from ..mylogger import logger 12 | from .forms import LoginForm, RegisterForm 13 | from ..tools import generate_id 14 | 15 | 16 | @main.route('/') 17 | def index(): 18 | logger.info('index') 19 | articles = Article().query.all() 20 | print(articles) 21 | return render_template('index.html', articles=articles, flag=1) 22 | 23 | 24 | @main.route('/login_in/', methods=['POST', 'GET']) 25 | def login_in(): 26 | loginForm = LoginForm() 27 | logger.debug('用户登录') 28 | if loginForm.validate_on_submit(): 29 | username = loginForm.username.data 30 | password = loginForm.password.data 31 | user = User.query.filter_by(user_name=username).first() 32 | if user is not None and user.verify_password(password): 33 | login_user(user, remember=loginForm.remember_me.data) 34 | return redirect(url_for('main.index')) 35 | return render_template('login.html', form=loginForm, action='/login_in/') 36 | 37 | 38 | @main.route('/login_up/', methods=['GET', 'POST']) 39 | def login_up(): 40 | registerForm = RegisterForm() 41 | logger.debug('用户注册') 42 | if registerForm.validate_on_submit(): 43 | username = registerForm.username.data 44 | user = User.query.filter_by(user_name=username).first() 45 | if user: 46 | flask('用户名已存在') 47 | email = registerForm.email.data 48 | passwd1 = registerForm.password.data 49 | passwd2 = registerForm.password2.data 50 | if passwd1 != passwd2: 51 | flash('两次密码不一致,请从新输入!') 52 | 53 | user = User(user_name=username, email=email, password=passwd1) 54 | user.user_id = generate_id('user') 55 | print('user=', user) 56 | db.session.add(user) 57 | db.session.commit() 58 | print('注册成功') 59 | return redirect(url_for('main.login_in')) 60 | return render_template('login_up.html', form=registerForm) 61 | 62 | 63 | @main.route('/login_out') 64 | @login_required 65 | def login_out(): 66 | logout_user() 67 | flash('You have been logged out.') 68 | return redirect(url_for('main.index')) 69 | 70 | 71 | @main.route('/get_article//') 72 | def get_article(article_id): 73 | article = Article().query.filter_by(article_id=article_id).first() 74 | article.article_read_cnt = article.article_read_cnt + 1 75 | db.session.add(article) 76 | db.session.commit() 77 | articles = Article().query.limit(8) 78 | comments = Comment().query.filter_by(article_id=article_id).all() 79 | return render_template( 80 | 'article.html', article=article, articles=articles, comments=comments) 81 | 82 | 83 | @main.route('/tasks/') 84 | @login_required 85 | def tasks(): 86 | tasks = Task().query.filter_by(user_id=current_user.user_id).all() 87 | return render_template('manage_task.html', tasks=tasks) 88 | 89 | 90 | @main.route('/add_task/', methods=['GET', 'POST']) 91 | @login_required 92 | def add_task(): 93 | if request.method == 'POST': 94 | task_name = request.form.get('task_name') 95 | emails = request.form.get('eamils') 96 | t_type = request.form.get('t_type') 97 | task_content = request.form.get('task_content') 98 | task_content = markdown.markdown(task_content, ['extra', 'codehilite']) 99 | task_id = generate_id('task') 100 | user_id = current_user.user_id 101 | start_dt = datetime.now().date() 102 | next_dt = datetime.now().date() + timedelta(days=1) 103 | task = Task( 104 | task_id=task_id, 105 | task_name=task_name, 106 | start_dt=str(start_dt), 107 | next_dt=str(next_dt), 108 | content=task_content, 109 | user_id=user_id, 110 | stat='进行中', 111 | remind=t_type) 112 | db.session.add(task) 113 | db.session.commit() 114 | print('add task finished') 115 | tasks = Task().query.filter_by(user_id=user_id).all() 116 | return render_template('manage_task.html', tasks=tasks) 117 | else: 118 | return render_template('add_task.html') 119 | 120 | 121 | @main.route('/del_task//') 122 | @login_required 123 | def del_task(task_id): 124 | task = Task().query.filter_by(task_id=taskid).first() 125 | db.session.delete(task) 126 | db.session.commit() 127 | print('del task finished') 128 | tasks = Task().query.filter_by(user_id=user_id).all() 129 | return render_template('manage_task.html', tasks=tasks) 130 | 131 | 132 | @main.route('/wrarticle/', methods=['GET', 'POST']) 133 | @login_required 134 | def wrarticle(): 135 | if request.method == 'POST': 136 | article_title = request.form.get('article_title') 137 | artitle_type = request.form.get('f_type') 138 | article_text = request.form.get('article_content') 139 | article_url = request.form.get('article_url') 140 | article_text = markdown.markdown(article_text, ['extra', 'codehilite']) 141 | 142 | article_id = generate_id('article') 143 | article_date = strftime('%Y-%m-%d %H:%M:%S') 144 | article_type = '技术杂谈' if artitle_type == '1' else '人生感悟' 145 | content = re.compile('.*?>(.*?)<').findall(article_text) 146 | article_summary = '' 147 | for x in content: 148 | if x: 149 | article_summary = article_summary + x 150 | if len(article_summary) > 250: 151 | break 152 | 153 | print('article_title=', article_title) 154 | print('article_type=', article_type) 155 | print('article_date=', article_date) 156 | article_summary = "".join(article_summary.split()) 157 | print('article_summary=', article_summary) 158 | article = Article( 159 | article_id=article_id, 160 | article_title=article_title, 161 | article_type=article_type, 162 | article_text=article_text, 163 | article_summary=article_summary[:180], 164 | article_url=article_url, 165 | article_date=article_date, 166 | user_id=current_user.user_id, 167 | article_author=current_user.user_name) 168 | db.session.add(article) 169 | db.session.commit() 170 | print('add article finished') 171 | articles = Article().query.limit(8) 172 | return render_template( 173 | 'article.html', article=article, articles=articles) 174 | else: 175 | return render_template('wrarticle.html') 176 | 177 | 178 | @main.route('/wrcomment/', methods=["POST"]) 179 | def wrcomment(article_id): 180 | print('article_id:', article_id) 181 | comment_name = request.form.get("name") 182 | commentary = request.form.get("commentary") 183 | commentary = markdown.markdown(commentary, ['extra', 'codehilite']) 184 | comment_id = generate_id('comment') 185 | comment_date = strftime('%Y-%m-%d %H:%M:%S') 186 | print('comment:', commentary) 187 | comment = Comment( 188 | comment_id=comment_id, 189 | comment_text=commentary, 190 | comment_date=comment_date, 191 | comment_name=comment_name, 192 | article_id=article_id) 193 | db.session.add(comment) 194 | db.session.commit() 195 | return redirect(url_for("main.get_article", article_id=article_id)) 196 | 197 | 198 | @main.route('/comment_oppose/') 199 | def comment_oppose(comment_id): 200 | comment = Comment().query.filter_by(comment_id=comment_id).first() 201 | comment.comment_oppose += 1 202 | db.session.add(comment) 203 | db.session.commit() 204 | return redirect(url_for("main.get_article", article_id=comment.article_id)) 205 | 206 | 207 | @main.route('/comment_support/') 208 | def comment_support(comment_id): 209 | print('comment_id:', comment_id) 210 | comment = Comment().query.filter_by(comment_id=comment_id).first() 211 | comment.comment_support += 1 212 | db.session.add(comment) 213 | db.session.commit() 214 | return redirect(url_for("main.get_article", article_id=comment.article_id)) 215 | 216 | 217 | @main.route('/del_article//') 218 | @login_required 219 | def del_article(article_id): 220 | article = Article().query.filter_by(article_id=article_id).first() 221 | db.session.delete(article) 222 | comments = Comment().query.filter_by(article_id=article_id).delete( 223 | synchronize_session=False) 224 | db.session.commit() 225 | print('删除文章成功!!!!') 226 | return redirect(url_for('main.manage_article')) 227 | 228 | 229 | @main.route('/manage_article/') 230 | @login_required 231 | def manage_article(): 232 | articles = Article().query.filter_by(user_id=current_user.user_id).all() 233 | return render_template('manage_article.html', articles=articles) 234 | 235 | 236 | @main.route('/technology/') 237 | def get_technology(): 238 | articles = Article().query.filter_by(article_type='技术杂谈').all() 239 | return render_template('index.html', articles=articles, flag=2) 240 | 241 | 242 | @main.route('/life/') 243 | def get_life(): 244 | articles = Article().query.filter_by(article_type='人生感悟').all() 245 | return render_template('index.html', articles=articles, flag=3) 246 | -------------------------------------------------------------------------------- /app/models.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Author: longzx 3 | # @Date: 2018-03-19 23:44:05 4 | # @cnblog:http://www.cnblogs.com/lonelyhiker/ 5 | from werkzeug.security import generate_password_hash, check_password_hash 6 | from itsdangerous import TimedJSONWebSignatureSerializer as Serializer 7 | from flask_login import UserMixin 8 | from flask import current_app 9 | 10 | from . import db, login_manager 11 | 12 | 13 | class Fiction(db.Model): 14 | __tablename__ = 'fiction' 15 | # __table_args__ = {"useexisting": True} 16 | id = db.Column(db.Integer, primary_key=True) 17 | fiction_name = db.Column(db.String) 18 | fiction_id = db.Column(db.String) 19 | fiction_real_url = db.Column(db.String) 20 | fiction_img = db.Column(db.String) 21 | fiction_author = db.Column(db.String) 22 | fiction_comment = db.Column(db.String) 23 | update = db.Column(db.String) 24 | new_content = db.Column(db.String) 25 | new_url = db.Column(db.String) 26 | 27 | def __repr__(self): 28 | return ' ' % self.fiction_name 29 | 30 | 31 | class Fiction_Lst(db.Model): 32 | __tablename__ = 'fiction_lst' 33 | # __table_args__ = {"useexisting": True} 34 | id = db.Column(db.Integer, primary_key=True) 35 | fiction_name = db.Column(db.String(255)) 36 | fiction_id = db.Column(db.String(255)) 37 | fiction_lst_url = db.Column(db.String(255)) 38 | fiction_lst_name = db.Column(db.String(255)) 39 | fiction_real_url = db.Column(db.String(255)) 40 | 41 | def __repr__(self): 42 | return ' ' % self.fiction_name 43 | 44 | 45 | class Fiction_Content(db.Model): 46 | __tablename__ = 'fiction_content' 47 | # __table_args__ = {"useexisting": True} 48 | id = db.Column(db.Integer, primary_key=True) 49 | fiction_url = db.Column(db.String(255)) 50 | fiction_content = db.Column(db.Text) 51 | fiction_id = db.Column(db.Integer) 52 | 53 | 54 | class User(UserMixin, db.Model): 55 | __tablename__ = 'user' 56 | user_id = db.Column(db.String(20), primary_key=True) 57 | user_name = db.Column(db.String(30), unique=True) 58 | nickname = db.Column(db.String(40), unique=True) 59 | sex = db.Column(db.String(4)) 60 | age = db.Column(db.Integer) 61 | password_hash = db.Column(db.String(128)) 62 | email = db.Column(db.String(50), unique=True) 63 | last_login_tm = db.Column(db.DateTime) 64 | user_crt_dt = db.Column(db.DateTime) 65 | attention_cnt = db.Column(db.Integer, default=0) 66 | 67 | def __repr__(self): 68 | return '<{},{},{}>'.format(self.user_name, self.email, self.user_id) 69 | 70 | # 增加密码属性 71 | @property 72 | def password(self): 73 | raise AttributeError('password is not a readable attribute') 74 | 75 | # 设置密码 76 | @password.setter 77 | def password(self, password): 78 | self.password_hash = generate_password_hash(password) 79 | 80 | # 校验密码 81 | def verify_password(self, password): 82 | return check_password_hash(self.password_hash, password) 83 | 84 | def get_id(self): 85 | return self.user_id 86 | 87 | def generate_auth_token(self, expiration=3600): 88 | #生成令牌字符串token 89 | s = Serializer(current_app.config['SECRET_KEY'], expires_in=expiration) 90 | return s.dumps({'user_id': self.user_id}).decode("utf-8") 91 | 92 | @staticmethod 93 | def verify_auth_token(token): 94 | s = Serializer(current_app.config['SECRET_KEY']) 95 | try: 96 | data = s.loads(token) 97 | except Exception: 98 | return None # valid token, but expired 99 | return User.query.get(data['user_id']) 100 | 101 | 102 | class Article(db.Model): 103 | __tablename__ = 'article' 104 | article_id = db.Column(db.String(20), primary_key=True) 105 | article_title = db.Column(db.String(100), nullable=False) 106 | article_text = db.Column(db.Text) 107 | article_summary = db.Column(db.String(255)) 108 | article_read_cnt = db.Column(db.Integer, default=0) 109 | article_sc = db.Column(db.Integer, default=0) 110 | article_pl = db.Column(db.Integer, default=0) 111 | article_date = db.Column(db.DateTime) 112 | article_url = db.Column(db.Text) 113 | article_type = db.Column(db.String(10)) 114 | article_author = db.Column(db.String(20)) 115 | user_id = db.Column(db.String(20)) 116 | 117 | 118 | class Comment(db.Model): 119 | __tablename__ = 'comment' 120 | comment_id = db.Column(db.String(20), primary_key=True) 121 | comment_text = db.Column(db.Text) 122 | comment_date = db.Column(db.DateTime) 123 | comment_name = db.Column(db.String(30)) 124 | comment_support = db.Column(db.Integer, default=0) 125 | comment_oppose = db.Column(db.Integer, default=0) 126 | article_id = db.Column(db.String(20), nullable=False) 127 | 128 | 129 | class Task(db.Model): 130 | __tablename__ = "task" 131 | task_id = db.Column(db.String(20), primary_key=True) 132 | task_name = db.Column(db.String(50), nullable=False) 133 | start_dt = db.Column(db.String(16)) 134 | next_dt = db.Column(db.String(16)) 135 | content = db.Column(db.String(200)) 136 | stat = db.Column(db.String(10)) 137 | remind = db.Column(db.String(10)) 138 | article_id = db.Column(db.String(20)) 139 | user_id = db.Column(db.String(20)) 140 | emails = db.Column(db.String(200)) 141 | stage = db.Column(db.Integer, default=1) 142 | 143 | 144 | # 公共参数表 145 | class Commparam(db.Model): 146 | __tablename__ = 'commparam' 147 | # 参数名称 148 | param_name = db.Column(db.String(10), primary_key=True) 149 | # 参数值1 150 | param_value = db.Column(db.Integer, default=1) 151 | # 参数值2 152 | param_text = db.Column(db.String(100)) 153 | # 参数状态 0-正常 1-停用 154 | param_stat = db.Column(db.String(2), default='0') 155 | 156 | 157 | # 加载用户的回调函数 158 | @login_manager.user_loader 159 | def load_user(user_id): 160 | print('call load_user') 161 | return User.query.get(user_id) 162 | -------------------------------------------------------------------------------- /app/mylogger.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Author: longzx 3 | # @Date: 2018-04-15 08:53:34 4 | # @cnblog:http://www.cnblogs.com/lonelyhiker/ 5 | import os 6 | from time import strftime 7 | import logging 8 | 9 | log_name = os.path.join( 10 | os.getenv('HOME'), 'log/flask/log_{}.log'.format(strftime('%Y%m%d'))) 11 | 12 | FLASK_LOG_FILE = os.getenv('FLASK_LOG_FILE') or log_name 13 | 14 | if not os.path.exists(os.path.dirname(FLASK_LOG_FILE)): 15 | os.makedirs(os.path.dirname(FLASK_LOG_FILE)) 16 | 17 | 18 | def init_logger(verbose=1, log_name=None): 19 | # 1.获取日志器 20 | logger = logging.getLogger(log_name) 21 | # 设置日志级别 22 | logger.setLevel(logging.DEBUG if verbose > 1 else logging.INFO) 23 | 24 | # 2.获取处理器 25 | f_handler = logging.FileHandler(FLASK_LOG_FILE, encoding='utf-8') 26 | formatter = logging.Formatter( 27 | '[%(asctime)s %(filename)s:%(lineno)s] - %(message)s') 28 | f_handler.setFormatter(formatter) 29 | f_handler.setLevel(logging.DEBUG) 30 | 31 | # 3.将处理器添加到日志器中 32 | logger.addHandler(f_handler) 33 | 34 | return logger 35 | 36 | 37 | logger = init_logger(log_name='flask') 38 | -------------------------------------------------------------------------------- /app/static/css/dashboard.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Base structure 3 | */ 4 | 5 | /* Move down content because we have a fixed navbar that is 50px tall */ 6 | body { 7 | padding-top: 50px; 8 | } 9 | 10 | 11 | /* 12 | * Global add-ons 13 | */ 14 | 15 | .sub-header { 16 | padding-bottom: 10px; 17 | border-bottom: 1px solid #eee; 18 | } 19 | 20 | /* 21 | * Top navigation 22 | * Hide default border to remove 1px line. 23 | */ 24 | .navbar-fixed-top { 25 | border: 0; 26 | } 27 | 28 | /* 29 | * Sidebar 30 | */ 31 | 32 | /* Hide for mobile, show later */ 33 | .sidebar { 34 | display: none; 35 | } 36 | @media (min-width: 768px) { 37 | .sidebar { 38 | position: fixed; 39 | top: 51px; 40 | bottom: 0; 41 | left: 0; 42 | z-index: 1000; 43 | display: block; 44 | padding: 20px; 45 | overflow-x: hidden; 46 | overflow-y: auto; /* Scrollable contents if viewport is shorter than content. */ 47 | background-color: #f5f5f5; 48 | border-right: 1px solid #eee; 49 | } 50 | } 51 | 52 | /* Sidebar navigation */ 53 | .nav-sidebar { 54 | margin-right: -21px; /* 20px padding + 1px border */ 55 | margin-bottom: 20px; 56 | margin-left: -20px; 57 | } 58 | .nav-sidebar > li > a { 59 | padding-right: 20px; 60 | padding-left: 20px; 61 | } 62 | .nav-sidebar > .active > a, 63 | .nav-sidebar > .active > a:hover, 64 | .nav-sidebar > .active > a:focus { 65 | color: #fff; 66 | background-color: #428bca; 67 | } 68 | 69 | 70 | /* 71 | * Main content 72 | */ 73 | 74 | .main { 75 | padding: 20px; 76 | } 77 | @media (min-width: 768px) { 78 | .main { 79 | padding-right: 40px; 80 | padding-left: 40px; 81 | } 82 | } 83 | .main .page-header { 84 | margin-top: 0; 85 | } 86 | 87 | 88 | /* 89 | * Placeholder dashboard ideas 90 | */ 91 | 92 | .placeholders { 93 | margin-bottom: 30px; 94 | text-align: center; 95 | } 96 | .placeholders h4 { 97 | margin-bottom: 0; 98 | } 99 | .placeholder { 100 | margin-bottom: 20px; 101 | } 102 | .placeholder img { 103 | display: inline-block; 104 | border-radius: 50%; 105 | } 106 | -------------------------------------------------------------------------------- /app/static/css/github-markdown.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: octicons-link; 3 | src: url(data:font/woff;charset=utf-8;base64,d09GRgABAAAAAAZwABAAAAAACFQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABEU0lHAAAGaAAAAAgAAAAIAAAAAUdTVUIAAAZcAAAACgAAAAoAAQAAT1MvMgAAAyQAAABJAAAAYFYEU3RjbWFwAAADcAAAAEUAAACAAJThvmN2dCAAAATkAAAABAAAAAQAAAAAZnBnbQAAA7gAAACyAAABCUM+8IhnYXNwAAAGTAAAABAAAAAQABoAI2dseWYAAAFsAAABPAAAAZwcEq9taGVhZAAAAsgAAAA0AAAANgh4a91oaGVhAAADCAAAABoAAAAkCA8DRGhtdHgAAAL8AAAADAAAAAwGAACfbG9jYQAAAsAAAAAIAAAACABiATBtYXhwAAACqAAAABgAAAAgAA8ASm5hbWUAAAToAAABQgAAAlXu73sOcG9zdAAABiwAAAAeAAAAME3QpOBwcmVwAAAEbAAAAHYAAAB/aFGpk3jaTY6xa8JAGMW/O62BDi0tJLYQincXEypYIiGJjSgHniQ6umTsUEyLm5BV6NDBP8Tpts6F0v+k/0an2i+itHDw3v2+9+DBKTzsJNnWJNTgHEy4BgG3EMI9DCEDOGEXzDADU5hBKMIgNPZqoD3SilVaXZCER3/I7AtxEJLtzzuZfI+VVkprxTlXShWKb3TBecG11rwoNlmmn1P2WYcJczl32etSpKnziC7lQyWe1smVPy/Lt7Kc+0vWY/gAgIIEqAN9we0pwKXreiMasxvabDQMM4riO+qxM2ogwDGOZTXxwxDiycQIcoYFBLj5K3EIaSctAq2kTYiw+ymhce7vwM9jSqO8JyVd5RH9gyTt2+J/yUmYlIR0s04n6+7Vm1ozezUeLEaUjhaDSuXHwVRgvLJn1tQ7xiuVv/ocTRF42mNgZGBgYGbwZOBiAAFGJBIMAAizAFoAAABiAGIAznjaY2BkYGAA4in8zwXi+W2+MjCzMIDApSwvXzC97Z4Ig8N/BxYGZgcgl52BCSQKAA3jCV8CAABfAAAAAAQAAEB42mNgZGBg4f3vACQZQABIMjKgAmYAKEgBXgAAeNpjYGY6wTiBgZWBg2kmUxoDA4MPhGZMYzBi1AHygVLYQUCaawqDA4PChxhmh/8ODDEsvAwHgMKMIDnGL0x7gJQCAwMAJd4MFwAAAHjaY2BgYGaA4DAGRgYQkAHyGMF8NgYrIM3JIAGVYYDT+AEjAwuDFpBmA9KMDEwMCh9i/v8H8sH0/4dQc1iAmAkALaUKLgAAAHjaTY9LDsIgEIbtgqHUPpDi3gPoBVyRTmTddOmqTXThEXqrob2gQ1FjwpDvfwCBdmdXC5AVKFu3e5MfNFJ29KTQT48Ob9/lqYwOGZxeUelN2U2R6+cArgtCJpauW7UQBqnFkUsjAY/kOU1cP+DAgvxwn1chZDwUbd6CFimGXwzwF6tPbFIcjEl+vvmM/byA48e6tWrKArm4ZJlCbdsrxksL1AwWn/yBSJKpYbq8AXaaTb8AAHja28jAwOC00ZrBeQNDQOWO//sdBBgYGRiYWYAEELEwMTE4uzo5Zzo5b2BxdnFOcALxNjA6b2ByTswC8jYwg0VlNuoCTWAMqNzMzsoK1rEhNqByEyerg5PMJlYuVueETKcd/89uBpnpvIEVomeHLoMsAAe1Id4AAAAAAAB42oWQT07CQBTGv0JBhagk7HQzKxca2sJCE1hDt4QF+9JOS0nbaaYDCQfwCJ7Au3AHj+LO13FMmm6cl7785vven0kBjHCBhfpYuNa5Ph1c0e2Xu3jEvWG7UdPDLZ4N92nOm+EBXuAbHmIMSRMs+4aUEd4Nd3CHD8NdvOLTsA2GL8M9PODbcL+hD7C1xoaHeLJSEao0FEW14ckxC+TU8TxvsY6X0eLPmRhry2WVioLpkrbp84LLQPGI7c6sOiUzpWIWS5GzlSgUzzLBSikOPFTOXqly7rqx0Z1Q5BAIoZBSFihQYQOOBEdkCOgXTOHA07HAGjGWiIjaPZNW13/+lm6S9FT7rLHFJ6fQbkATOG1j2OFMucKJJsxIVfQORl+9Jyda6Sl1dUYhSCm1dyClfoeDve4qMYdLEbfqHf3O/AdDumsjAAB42mNgYoAAZQYjBmyAGYQZmdhL8zLdDEydARfoAqIAAAABAAMABwAKABMAB///AA8AAQAAAAAAAAAAAAAAAAABAAAAAA==) format('woff'); 4 | } 5 | 6 | .markdown-body { 7 | -ms-text-size-adjust: 100%; 8 | -webkit-text-size-adjust: 100%; 9 | line-height: 1.5; 10 | color: #24292e; 11 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; 12 | font-size: 16px; 13 | line-height: 1.5; 14 | word-wrap: break-word; 15 | } 16 | 17 | .markdown-body .pl-c { 18 | color: #6a737d; 19 | } 20 | 21 | .markdown-body .pl-c1, 22 | .markdown-body .pl-s .pl-v { 23 | color: #005cc5; 24 | } 25 | 26 | .markdown-body .pl-e, 27 | .markdown-body .pl-en { 28 | color: #6f42c1; 29 | } 30 | 31 | .markdown-body .pl-smi, 32 | .markdown-body .pl-s .pl-s1 { 33 | color: #24292e; 34 | } 35 | 36 | .markdown-body .pl-ent { 37 | color: #22863a; 38 | } 39 | 40 | .markdown-body .pl-k { 41 | color: #d73a49; 42 | } 43 | 44 | .markdown-body .pl-s, 45 | .markdown-body .pl-pds, 46 | .markdown-body .pl-s .pl-pse .pl-s1, 47 | .markdown-body .pl-sr, 48 | .markdown-body .pl-sr .pl-cce, 49 | .markdown-body .pl-sr .pl-sre, 50 | .markdown-body .pl-sr .pl-sra { 51 | color: #032f62; 52 | } 53 | 54 | .markdown-body .pl-v, 55 | .markdown-body .pl-smw { 56 | color: #e36209; 57 | } 58 | 59 | .markdown-body .pl-bu { 60 | color: #b31d28; 61 | } 62 | 63 | .markdown-body .pl-ii { 64 | color: #fafbfc; 65 | background-color: #b31d28; 66 | } 67 | 68 | .markdown-body .pl-c2 { 69 | color: #fafbfc; 70 | background-color: #d73a49; 71 | } 72 | 73 | .markdown-body .pl-c2::before { 74 | content: "^M"; 75 | } 76 | 77 | .markdown-body .pl-sr .pl-cce { 78 | font-weight: bold; 79 | color: #22863a; 80 | } 81 | 82 | .markdown-body .pl-ml { 83 | color: #735c0f; 84 | } 85 | 86 | .markdown-body .pl-mh, 87 | .markdown-body .pl-mh .pl-en, 88 | .markdown-body .pl-ms { 89 | font-weight: bold; 90 | color: #005cc5; 91 | } 92 | 93 | .markdown-body .pl-mi { 94 | font-style: italic; 95 | color: #24292e; 96 | } 97 | 98 | .markdown-body .pl-mb { 99 | font-weight: bold; 100 | color: #24292e; 101 | } 102 | 103 | .markdown-body .pl-md { 104 | color: #b31d28; 105 | background-color: #ffeef0; 106 | } 107 | 108 | .markdown-body .pl-mi1 { 109 | color: #22863a; 110 | background-color: #f0fff4; 111 | } 112 | 113 | .markdown-body .pl-mc { 114 | color: #e36209; 115 | background-color: #ffebda; 116 | } 117 | 118 | .markdown-body .pl-mi2 { 119 | color: #f6f8fa; 120 | background-color: #005cc5; 121 | } 122 | 123 | .markdown-body .pl-mdr { 124 | font-weight: bold; 125 | color: #6f42c1; 126 | } 127 | 128 | .markdown-body .pl-ba { 129 | color: #586069; 130 | } 131 | 132 | .markdown-body .pl-sg { 133 | color: #959da5; 134 | } 135 | 136 | .markdown-body .pl-corl { 137 | text-decoration: underline; 138 | color: #032f62; 139 | } 140 | 141 | .markdown-body .octicon { 142 | display: inline-block; 143 | vertical-align: text-top; 144 | fill: currentColor; 145 | } 146 | 147 | .markdown-body a { 148 | background-color: transparent; 149 | } 150 | 151 | .markdown-body a:active, 152 | .markdown-body a:hover { 153 | outline-width: 0; 154 | } 155 | 156 | .markdown-body strong { 157 | font-weight: inherit; 158 | } 159 | 160 | .markdown-body strong { 161 | font-weight: bolder; 162 | } 163 | 164 | .markdown-body h1 { 165 | font-size: 2em; 166 | margin: 0.67em 0; 167 | } 168 | 169 | .markdown-body img { 170 | border-style: none; 171 | } 172 | 173 | .markdown-body code, 174 | .markdown-body kbd, 175 | .markdown-body pre { 176 | font-family: monospace, monospace; 177 | font-size: 1em; 178 | } 179 | 180 | .markdown-body hr { 181 | box-sizing: content-box; 182 | height: 0; 183 | overflow: visible; 184 | } 185 | 186 | .markdown-body input { 187 | font: inherit; 188 | margin: 0; 189 | } 190 | 191 | .markdown-body input { 192 | overflow: visible; 193 | } 194 | 195 | .markdown-body [type="checkbox"] { 196 | box-sizing: border-box; 197 | padding: 0; 198 | } 199 | 200 | .markdown-body * { 201 | box-sizing: border-box; 202 | } 203 | 204 | .markdown-body input { 205 | font-family: inherit; 206 | font-size: inherit; 207 | line-height: inherit; 208 | } 209 | 210 | .markdown-body a { 211 | color: #0366d6; 212 | text-decoration: none; 213 | } 214 | 215 | .markdown-body a:hover { 216 | text-decoration: underline; 217 | } 218 | 219 | .markdown-body strong { 220 | font-weight: 600; 221 | } 222 | 223 | .markdown-body hr { 224 | height: 0; 225 | margin: 15px 0; 226 | overflow: hidden; 227 | background: transparent; 228 | border: 0; 229 | border-bottom: 1px solid #dfe2e5; 230 | } 231 | 232 | .markdown-body hr::before { 233 | display: table; 234 | content: ""; 235 | } 236 | 237 | .markdown-body hr::after { 238 | display: table; 239 | clear: both; 240 | content: ""; 241 | } 242 | 243 | .markdown-body table { 244 | border-spacing: 0; 245 | border-collapse: collapse; 246 | } 247 | 248 | .markdown-body td, 249 | .markdown-body th { 250 | padding: 0; 251 | } 252 | 253 | .markdown-body h1, 254 | .markdown-body h2, 255 | .markdown-body h3, 256 | .markdown-body h4, 257 | .markdown-body h5, 258 | .markdown-body h6 { 259 | margin-top: 0; 260 | margin-bottom: 0; 261 | } 262 | 263 | .markdown-body h1 { 264 | font-size: 32px; 265 | font-weight: 600; 266 | } 267 | 268 | .markdown-body h2 { 269 | font-size: 24px; 270 | font-weight: 600; 271 | } 272 | 273 | .markdown-body h3 { 274 | font-size: 20px; 275 | font-weight: 600; 276 | } 277 | 278 | .markdown-body h4 { 279 | font-size: 16px; 280 | font-weight: 600; 281 | } 282 | 283 | .markdown-body h5 { 284 | font-size: 14px; 285 | font-weight: 600; 286 | } 287 | 288 | .markdown-body h6 { 289 | font-size: 12px; 290 | font-weight: 600; 291 | } 292 | 293 | .markdown-body p { 294 | margin-top: 0; 295 | margin-bottom: 10px; 296 | } 297 | 298 | .markdown-body blockquote { 299 | margin: 0; 300 | } 301 | 302 | .markdown-body ul, 303 | .markdown-body ol { 304 | padding-left: 0; 305 | margin-top: 0; 306 | margin-bottom: 0; 307 | } 308 | 309 | .markdown-body ol ol, 310 | .markdown-body ul ol { 311 | list-style-type: lower-roman; 312 | } 313 | 314 | .markdown-body ul ul ol, 315 | .markdown-body ul ol ol, 316 | .markdown-body ol ul ol, 317 | .markdown-body ol ol ol { 318 | list-style-type: lower-alpha; 319 | } 320 | 321 | .markdown-body dd { 322 | margin-left: 0; 323 | } 324 | 325 | .markdown-body code { 326 | font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace; 327 | font-size: 12px; 328 | } 329 | 330 | .markdown-body pre { 331 | margin-top: 0; 332 | margin-bottom: 0; 333 | font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace; 334 | font-size: 12px; 335 | } 336 | 337 | .markdown-body .octicon { 338 | vertical-align: text-bottom; 339 | } 340 | 341 | .markdown-body .pl-0 { 342 | padding-left: 0 !important; 343 | } 344 | 345 | .markdown-body .pl-1 { 346 | padding-left: 4px !important; 347 | } 348 | 349 | .markdown-body .pl-2 { 350 | padding-left: 8px !important; 351 | } 352 | 353 | .markdown-body .pl-3 { 354 | padding-left: 16px !important; 355 | } 356 | 357 | .markdown-body .pl-4 { 358 | padding-left: 24px !important; 359 | } 360 | 361 | .markdown-body .pl-5 { 362 | padding-left: 32px !important; 363 | } 364 | 365 | .markdown-body .pl-6 { 366 | padding-left: 40px !important; 367 | } 368 | 369 | .markdown-body::before { 370 | display: table; 371 | content: ""; 372 | } 373 | 374 | .markdown-body::after { 375 | display: table; 376 | clear: both; 377 | content: ""; 378 | } 379 | 380 | .markdown-body>*:first-child { 381 | margin-top: 0 !important; 382 | } 383 | 384 | .markdown-body>*:last-child { 385 | margin-bottom: 0 !important; 386 | } 387 | 388 | .markdown-body a:not([href]) { 389 | color: inherit; 390 | text-decoration: none; 391 | } 392 | 393 | .markdown-body .anchor { 394 | float: left; 395 | padding-right: 4px; 396 | margin-left: -20px; 397 | line-height: 1; 398 | } 399 | 400 | .markdown-body .anchor:focus { 401 | outline: none; 402 | } 403 | 404 | .markdown-body p, 405 | .markdown-body blockquote, 406 | .markdown-body ul, 407 | .markdown-body ol, 408 | .markdown-body dl, 409 | .markdown-body table, 410 | .markdown-body pre { 411 | margin-top: 0; 412 | margin-bottom: 16px; 413 | } 414 | 415 | .markdown-body hr { 416 | height: 0.25em; 417 | padding: 0; 418 | margin: 24px 0; 419 | background-color: #e1e4e8; 420 | border: 0; 421 | } 422 | 423 | .markdown-body blockquote { 424 | padding: 0 1em; 425 | color: #6a737d; 426 | border-left: 0.25em solid #dfe2e5; 427 | } 428 | 429 | .markdown-body blockquote>:first-child { 430 | margin-top: 0; 431 | } 432 | 433 | .markdown-body blockquote>:last-child { 434 | margin-bottom: 0; 435 | } 436 | 437 | .markdown-body kbd { 438 | display: inline-block; 439 | padding: 3px 5px; 440 | font-size: 11px; 441 | line-height: 10px; 442 | color: #444d56; 443 | vertical-align: middle; 444 | background-color: #fafbfc; 445 | border: solid 1px #c6cbd1; 446 | border-bottom-color: #959da5; 447 | border-radius: 3px; 448 | box-shadow: inset 0 -1px 0 #959da5; 449 | } 450 | 451 | .markdown-body h1, 452 | .markdown-body h2, 453 | .markdown-body h3, 454 | .markdown-body h4, 455 | .markdown-body h5, 456 | .markdown-body h6 { 457 | margin-top: 24px; 458 | margin-bottom: 16px; 459 | font-weight: 600; 460 | line-height: 1.25; 461 | } 462 | 463 | .markdown-body h1 .octicon-link, 464 | .markdown-body h2 .octicon-link, 465 | .markdown-body h3 .octicon-link, 466 | .markdown-body h4 .octicon-link, 467 | .markdown-body h5 .octicon-link, 468 | .markdown-body h6 .octicon-link { 469 | color: #1b1f23; 470 | vertical-align: middle; 471 | visibility: hidden; 472 | } 473 | 474 | .markdown-body h1:hover .anchor, 475 | .markdown-body h2:hover .anchor, 476 | .markdown-body h3:hover .anchor, 477 | .markdown-body h4:hover .anchor, 478 | .markdown-body h5:hover .anchor, 479 | .markdown-body h6:hover .anchor { 480 | text-decoration: none; 481 | } 482 | 483 | .markdown-body h1:hover .anchor .octicon-link, 484 | .markdown-body h2:hover .anchor .octicon-link, 485 | .markdown-body h3:hover .anchor .octicon-link, 486 | .markdown-body h4:hover .anchor .octicon-link, 487 | .markdown-body h5:hover .anchor .octicon-link, 488 | .markdown-body h6:hover .anchor .octicon-link { 489 | visibility: visible; 490 | } 491 | 492 | .markdown-body h1 { 493 | padding-bottom: 0.3em; 494 | font-size: 2em; 495 | border-bottom: 1px solid #eaecef; 496 | } 497 | 498 | .markdown-body h2 { 499 | padding-bottom: 0.3em; 500 | font-size: 1.5em; 501 | border-bottom: 1px solid #eaecef; 502 | } 503 | 504 | .markdown-body h3 { 505 | font-size: 1.25em; 506 | } 507 | 508 | .markdown-body h4 { 509 | font-size: 1em; 510 | } 511 | 512 | .markdown-body h5 { 513 | font-size: 0.875em; 514 | } 515 | 516 | .markdown-body h6 { 517 | font-size: 0.85em; 518 | color: #6a737d; 519 | } 520 | 521 | .markdown-body ul, 522 | .markdown-body ol { 523 | padding-left: 2em; 524 | } 525 | 526 | .markdown-body ul ul, 527 | .markdown-body ul ol, 528 | .markdown-body ol ol, 529 | .markdown-body ol ul { 530 | margin-top: 0; 531 | margin-bottom: 0; 532 | } 533 | 534 | .markdown-body li { 535 | word-wrap: break-all; 536 | } 537 | 538 | .markdown-body li>p { 539 | margin-top: 16px; 540 | } 541 | 542 | .markdown-body li+li { 543 | margin-top: 0.25em; 544 | } 545 | 546 | .markdown-body dl { 547 | padding: 0; 548 | } 549 | 550 | .markdown-body dl dt { 551 | padding: 0; 552 | margin-top: 16px; 553 | font-size: 1em; 554 | font-style: italic; 555 | font-weight: 600; 556 | } 557 | 558 | .markdown-body dl dd { 559 | padding: 0 16px; 560 | margin-bottom: 16px; 561 | } 562 | 563 | .markdown-body table { 564 | display: block; 565 | width: 100%; 566 | overflow: auto; 567 | } 568 | 569 | .markdown-body table th { 570 | font-weight: 600; 571 | } 572 | 573 | .markdown-body table th, 574 | .markdown-body table td { 575 | padding: 6px 13px; 576 | border: 1px solid #dfe2e5; 577 | } 578 | 579 | .markdown-body table tr { 580 | background-color: #fff; 581 | border-top: 1px solid #c6cbd1; 582 | } 583 | 584 | .markdown-body table tr:nth-child(2n) { 585 | background-color: #f6f8fa; 586 | } 587 | 588 | .markdown-body img { 589 | max-width: 100%; 590 | box-sizing: content-box; 591 | background-color: #fff; 592 | } 593 | 594 | .markdown-body img[align=right] { 595 | padding-left: 20px; 596 | } 597 | 598 | .markdown-body img[align=left] { 599 | padding-right: 20px; 600 | } 601 | 602 | .markdown-body code { 603 | padding: 0.2em 0.4em; 604 | margin: 0; 605 | font-size: 85%; 606 | background-color: rgba(27,31,35,0.05); 607 | border-radius: 3px; 608 | } 609 | 610 | .markdown-body pre { 611 | word-wrap: normal; 612 | } 613 | 614 | .markdown-body pre>code { 615 | padding: 0; 616 | margin: 0; 617 | font-size: 100%; 618 | word-break: normal; 619 | white-space: pre; 620 | background: transparent; 621 | border: 0; 622 | } 623 | 624 | .markdown-body .highlight { 625 | margin-bottom: 16px; 626 | } 627 | 628 | .markdown-body .highlight pre { 629 | margin-bottom: 0; 630 | word-break: normal; 631 | } 632 | 633 | .markdown-body .highlight pre, 634 | .markdown-body pre { 635 | padding: 16px; 636 | overflow: auto; 637 | font-size: 85%; 638 | line-height: 1.45; 639 | background-color: #f6f8fa; 640 | border-radius: 3px; 641 | } 642 | 643 | .markdown-body pre code { 644 | display: inline; 645 | max-width: auto; 646 | padding: 0; 647 | margin: 0; 648 | overflow: visible; 649 | line-height: inherit; 650 | word-wrap: normal; 651 | background-color: transparent; 652 | border: 0; 653 | } 654 | 655 | .markdown-body .full-commit .btn-outline:not(:disabled):hover { 656 | color: #005cc5; 657 | border-color: #005cc5; 658 | } 659 | 660 | .markdown-body kbd { 661 | display: inline-block; 662 | padding: 3px 5px; 663 | font: 11px "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace; 664 | line-height: 10px; 665 | color: #444d56; 666 | vertical-align: middle; 667 | background-color: #fafbfc; 668 | border: solid 1px #d1d5da; 669 | border-bottom-color: #c6cbd1; 670 | border-radius: 3px; 671 | box-shadow: inset 0 -1px 0 #c6cbd1; 672 | } 673 | 674 | .markdown-body :checked+.radio-label { 675 | position: relative; 676 | z-index: 1; 677 | border-color: #0366d6; 678 | } 679 | 680 | .markdown-body .task-list-item { 681 | list-style-type: none; 682 | } 683 | 684 | .markdown-body .task-list-item+.task-list-item { 685 | margin-top: 3px; 686 | } 687 | 688 | .markdown-body .task-list-item input { 689 | margin: 0 0.2em 0.25em -1.6em; 690 | vertical-align: middle; 691 | } 692 | 693 | .markdown-body hr { 694 | border-bottom-color: #eee; 695 | } 696 | -------------------------------------------------------------------------------- /app/static/css/ie10-viewport-bug-workaround.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * IE10 viewport hack for Surface/desktop Windows 8 bug 3 | * Copyright 2014-2015 Twitter, Inc. 4 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) 5 | */ 6 | 7 | /* 8 | * See the Getting Started docs for more information: 9 | * http://getbootstrap.com/getting-started/#support-ie10-width 10 | */ 11 | @-ms-viewport { width: device-width; } 12 | @-o-viewport { width: device-width; } 13 | @viewport { width: device-width; } 14 | -------------------------------------------------------------------------------- /app/static/css/mycss.css: -------------------------------------------------------------------------------- 1 | body { 2 | /* color: #505050; */ 3 | line-height: 1.75em; 4 | /* background: #ebebeb; */ 5 | position: relative; 6 | height: 100%; 7 | font-family: "Helvetica Neue", Helvetica, Arial, "Hiragino Sans GB", "Hiragino Sans GB W3", "WenQuanYi Micro Hei", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif; 8 | 9 | } 10 | 11 | #footer{ 12 | margin-top: 20px; 13 | min-width: 100%; 14 | float: left; 15 | background: #3C3C3C; 16 | } 17 | #footer .footer-c{ 18 | width: 1190px; 19 | margin: 0 auto; 20 | } 21 | #footer .footer-c ul{ 22 | width: 1190px; 23 | text-align: center; 24 | float: left; 25 | margin: 0 auto; 26 | /*background: blue;*/ 27 | } 28 | #footer .footer-c ul li{ 29 | display: inline-block; 30 | margin: 20px; 31 | } 32 | #footer .footer-c ul li a { 33 | color: #fff; 34 | font-size: 14px; 35 | } 36 | #footer .footer-c ul li a:hover{ 37 | color: #ff6600; 38 | } 39 | #footer .footer-c p{ 40 | font-size: 12px; 41 | color: #C2C2C2; 42 | text-align: center; 43 | padding-bottom: 15px; 44 | } 45 | #footer .footer-c p a{ 46 | color: #fff; 47 | } 48 | 49 | -------------------------------------------------------------------------------- /app/static/css/xscss.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #E9FAFF; 3 | color: #555; 4 | font-family: 宋体; 5 | font-size: 14px; 6 | margin: 0 auto; 7 | } 8 | .box_con { 9 | border: 2px solid #88C6E5; 10 | overflow: hidden; 11 | width: 976px; 12 | margin: 10px auto; 13 | font-size: 16px; 14 | } 15 | .box_cons { 16 | border: 2px solid #88C6E5; 17 | overflow: hidden; 18 | width: 100px auto; 19 | margin: 10px auto; 20 | } 21 | .box_zhangj{ 22 | border: 2px solid #88C6E5; 23 | overflow: hidden; 24 | width: 100%; 25 | margin: 10px auto; 26 | } 27 | .box_section{ 28 | border-top: 2px solid #88C6E5; 29 | border-bottom: 2px solid #88C6E5; 30 | overflow: hidden; 31 | width: 100%; 32 | margin: 10px auto; 33 | } 34 | #list { 35 | padding: 2px; 36 | padding-top: 2px; 37 | padding-right: 2px; 38 | padding-bottom: 2px; 39 | padding-left: 2px; 40 | } 41 | #list dl { 42 | float: left; 43 | overflow: hidden; 44 | padding-bottom: 1px; 45 | margin: auto; 46 | } 47 | #list dt { 48 | background: none repeat scroll 0 0 #C3DFEA; 49 | display: inline; 50 | float: left; 51 | font-size: 18px; 52 | line-height: 28px; 53 | overflow: hidden; 54 | text-align: center; 55 | vertical-align: middle; 56 | width: 100%; 57 | margin: auto auto 5px; 58 | padding: 5px 10px; 59 | } 60 | #list dd { 61 | border-bottom: 1px dashed #CCC; 62 | display: inline; 63 | float: left; 64 | height: 25px; 65 | line-height: 200%; 66 | margin-bottom: 5px; 67 | overflow: hidden; 68 | text-align: left; 69 | text-indent: 10px; 70 | vertical-align: middle; 71 | width: 33%; 72 | } 73 | 74 | 75 | #footererror{ 76 | margin-top: 20px; 77 | min-width: 100%; 78 | float: left; 79 | position: fixed; 80 | bottom: 0; 81 | background: #3C3C3C; 82 | } 83 | #footererror .footererror-c{ 84 | width: 1190px; 85 | margin: 0 auto; 86 | } 87 | #footererror .footererror-c ul{ 88 | width: 1190px; 89 | text-align: center; 90 | float: left; 91 | margin: 0 auto; 92 | /*background: blue;*/ 93 | } 94 | #footererror .footererror-c ul li{ 95 | display: inline-block; 96 | margin: 20px; 97 | } 98 | #footererror .footererror-c ul li a { 99 | color: #fff; 100 | font-size: 14px; 101 | } 102 | #footererror .footererror-c ul li a:hover{ 103 | color: #ff6600; 104 | } 105 | #footererror .footererror-c p{ 106 | font-size: 12px; 107 | color: #C2C2C2; 108 | text-align: center; 109 | padding-bottom: 15px; 110 | } 111 | #footererror .footererror-c p a{ 112 | color: #fff; 113 | } 114 | -------------------------------------------------------------------------------- /app/static/js/ie-emulation-modes-warning.js: -------------------------------------------------------------------------------- 1 | // NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT 2 | // IT'S JUST JUNK FOR OUR DOCS! 3 | // ++++++++++++++++++++++++++++++++++++++++++ 4 | /*! 5 | * Copyright 2014-2015 Twitter, Inc. 6 | * 7 | * Licensed under the Creative Commons Attribution 3.0 Unported License. For 8 | * details, see https://creativecommons.org/licenses/by/3.0/. 9 | */ 10 | // Intended to prevent false-positive bug reports about Bootstrap not working properly in old versions of IE due to folks testing using IE's unreliable emulation modes. 11 | (function () { 12 | 'use strict'; 13 | 14 | function emulatedIEMajorVersion() { 15 | var groups = /MSIE ([0-9.]+)/.exec(window.navigator.userAgent) 16 | if (groups === null) { 17 | return null 18 | } 19 | var ieVersionNum = parseInt(groups[1], 10) 20 | var ieMajorVersion = Math.floor(ieVersionNum) 21 | return ieMajorVersion 22 | } 23 | 24 | function actualNonEmulatedIEMajorVersion() { 25 | // Detects the actual version of IE in use, even if it's in an older-IE emulation mode. 26 | // IE JavaScript conditional compilation docs: https://msdn.microsoft.com/library/121hztk3%28v=vs.94%29.aspx 27 | // @cc_on docs: https://msdn.microsoft.com/library/8ka90k2e%28v=vs.94%29.aspx 28 | var jscriptVersion = new Function('/*@cc_on return @_jscript_version; @*/')() // jshint ignore:line 29 | if (jscriptVersion === undefined) { 30 | return 11 // IE11+ not in emulation mode 31 | } 32 | if (jscriptVersion < 9) { 33 | return 8 // IE8 (or lower; haven't tested on IE<8) 34 | } 35 | return jscriptVersion // IE9 or IE10 in any mode, or IE11 in non-IE11 mode 36 | } 37 | 38 | var ua = window.navigator.userAgent 39 | if (ua.indexOf('Opera') > -1 || ua.indexOf('Presto') > -1) { 40 | return // Opera, which might pretend to be IE 41 | } 42 | var emulated = emulatedIEMajorVersion() 43 | if (emulated === null) { 44 | return // Not IE 45 | } 46 | var nonEmulated = actualNonEmulatedIEMajorVersion() 47 | 48 | if (emulated !== nonEmulated) { 49 | window.alert('WARNING: You appear to be using IE' + nonEmulated + ' in IE' + emulated + ' emulation mode.\nIE emulation modes can behave significantly differently from ACTUAL older versions of IE.\nPLEASE DON\'T FILE BOOTSTRAP BUGS based on testing in IE emulation modes!') 50 | } 51 | })(); 52 | -------------------------------------------------------------------------------- /app/templates/add_task.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | 3 | {% block content%} 4 |
5 |
6 |
7 |
8 |
9 | 10 | 11 |
12 |
13 | 14 |
15 | 16 | 17 |
18 |
19 | 20 |
21 |
22 | 23 | 26 | 29 |
30 | 31 |
32 | 33 | 34 |
35 |
36 | 37 |
38 |
39 |
40 | 41 | 42 | 43 | 44 | 45 | 56 | 66 | 67 | 68 | {{super()}} 69 | {% endblock %} 70 | -------------------------------------------------------------------------------- /app/templates/article.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | 3 | {% block content%} 4 | 5 |
6 |
7 | 8 |
9 | 10 | 15 | 16 |
17 |
18 |

{{article.article_title}}

19 |

20 | {{article.article_author}}   21 | {{article.article_date}}   22 | 浏览({{article.article_read_cnt}})   23 | 收藏({{article.article_sc}})   24 | 评论({{article.article_pl}})   25 |

26 |
27 | 28 | 29 |
30 | {{article.article_text|safe}} 31 |
32 |
33 | 34 |
35 |
36 | 37 |
38 | 39 |
40 |
41 | 42 |
43 |
44 | 45 |
46 |
47 | 48 |
49 |
50 | 51 |
52 |
53 | 54 |
55 | 56 |

57 | 评论列表 58 |

59 |
60 | {% for comment in comments%} 61 |
62 |

#{{loop.index}}楼 {{comment.comment_date}} {{comment.comment_name}}

63 |

64 | {{comment.comment_text|safe}} 65 |

支持({{comment.comment_support}})

66 |

反对({{comment.comment_oppose}})

67 |

68 |
69 | {% endfor %} 70 |
71 | 72 |
73 |
74 |
75 |
76 | 77 |
78 | 79 |
80 |
81 | 猜你喜欢 82 | {% for article in articles %} 83 |
84 |
85 | 86 | 87 |
88 |

{{article.article_title}}

89 |

90 | {{article.article_date}} 评论({{article.article_pl}}) 91 |

92 |
93 | 94 |
95 |
96 | {% endfor %} 97 | 98 |
99 |
100 | 101 | 102 | 103 |
104 |
105 | 106 | 107 | {{super()}} 108 | {% endblock %} 109 | -------------------------------------------------------------------------------- /app/templates/base.html: -------------------------------------------------------------------------------- 1 | {% extends "bootstrap/base.html" %} 2 | {% block title %} 人生苦短、我用python{% endblock title %} 3 | {%- block styles %} 4 | {{super()}} 5 | 6 | 7 | 8 | 9 | 42 | {%- endblock styles %} 43 | 44 | {% block navbar %} 45 | 46 | 102 |
103 |
104 | {% endblock navbar %} 105 | 106 | {% block content %} 107 |
108 |
109 | 110 | 124 | 125 | {% endblock %} 126 | 127 | 128 | -------------------------------------------------------------------------------- /app/templates/base_login.html: -------------------------------------------------------------------------------- 1 | {% extends "bootstrap/base.html" %} 2 | 3 | {% block title %}登录注册{% endblock title %} 4 | 5 | {% block meta %} 6 | {{ supper() }} 7 | 8 | 9 | 10 | {% endblock meta %} 11 | {% block styles %} 12 | {{ super() }} 13 | 14 | 19 | } 20 | {% endblock %} 21 | 22 | 23 | {% block navbar %} 24 | 47 | {% endblock navbar %} 48 | 49 | -------------------------------------------------------------------------------- /app/templates/fiction.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% block styles %} 3 | {{super()}} 4 | 5 | {% endblock %} 6 | {% block content %} 7 | 8 |
9 |
10 | 11 |
12 |
13 |
14 |
15 |

{{fiction_name}}

16 |
17 |
18 |

19 | 上一章 20 | ← 21 | 章节列表 22 | → 23 | {% if fiction_next %} 24 | 25 | {% endif %} 26 |

27 |
28 |
29 | {{fiction_content|safe}} 30 |
31 |

32 | 上一章 33 | ← 34 | 章节列表 35 | → 36 | {% if fiction_next %} 37 | 38 | {% endif %} 39 |

40 |
41 |
42 |
43 |
44 | 45 |
46 |
47 | 48 | {{super()}} 49 | {% endblock%} 50 | -------------------------------------------------------------------------------- /app/templates/fiction_error.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | 3 | {% block styles %} 4 | {{super()}} 5 | 6 | {% endblock %} 7 | {% block content %} 8 | 9 | 10 |
11 |
12 |
13 | 19 |
20 |
21 |
22 |
23 | 24 | 25 |
26 | 27 |
28 |
29 |
30 |

{{message}}

31 |
32 |
33 |
34 |
35 | 36 |
37 |
38 |
39 | 45 |
46 |

© 2012-2016 jqhtml.com · 湘ICP备16001111号-1 · 托管于 阿里云 & 又拍云

47 |

48 | 57 |

58 | 62 |
63 |
64 | {% endblock %} 65 | -------------------------------------------------------------------------------- /app/templates/fiction_index.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | 3 | {% block styles %} 4 | {{super()}} 5 | 6 | {% endblock %} 7 | {% block content %} 8 | 9 | 10 |
11 |
12 |
13 | 19 |
20 |
21 |
22 |
23 | 24 |
25 | 26 |
27 |
28 | 29 | 30 | 31 |
32 |
33 |
34 |
35 |
热门小说
36 | 41 |
42 |
43 |
44 | 45 |
46 |
47 |
48 | {% for fiction in fictions %} 49 | {% if loop.index0 % 2 == 0 %} 50 |
51 | {% endif %} 52 |
53 |
54 | 55 |
56 | 57 |
{{fiction.fiction_author}}
58 |
59 | {{fiction.fiction_comment}}... 60 |
61 |
62 |
63 | {% if loop.index % 2 == 0 or loop.last %} 64 |
65 |
66 | {% endif %} 67 | {% endfor %} 68 |
69 |
70 | 71 |
72 | 73 | 74 |
75 |
76 | 77 |
78 | {{super()}} 79 | {% endblock %} 80 | 81 | 82 | -------------------------------------------------------------------------------- /app/templates/fiction_lst.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% block styles %} 3 | {{super()}} 4 | 5 | {% endblock %} 6 | {% block content %} 7 | 8 |
9 |
10 | 11 |
12 |
13 |
14 |
热门小说
15 | 20 |
21 |
22 |
23 | 24 |
25 | 26 |
27 |
28 |
29 | 30 |
31 |

{{fiction.fiction_name}}

32 |

作    者:{{fiction.fiction_author}}

33 |
34 |

{{fiction.update}}     {{fiction.new_content}}

35 | 更新 36 |
37 |
38 |
39 | {{fiction.fiction_comment}}... 40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
《{{fiction_name}}》最新章节
49 | {% for item in fiction_lst[-9:] %} 50 |
{{item.fiction_lst_name}}
51 | {% endfor %} 52 |
53 |
54 |
55 | 56 |
57 |
58 |
59 |
《{{fiction_name}}》章节目录
60 | {% for item in fiction_lst %} 61 |
{{item.fiction_lst_name}}
62 | {% endfor %} 63 |
64 |
65 |
66 | 67 |
68 | 69 | 70 |
71 |
72 | 73 | {{super()}} 74 | {% endblock%} 75 | -------------------------------------------------------------------------------- /app/templates/index.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% block content %} 3 | 4 | 5 |
6 |
7 | 8 | 9 |
10 | 11 |
12 |
13 |

热门排行

14 |
15 | {% for article in articles[:8] %} 16 |
17 |
18 | {{loop.index}} 19 | {{article.article_title}} 20 |

 喜欢 ({{article.article_sc}})  

21 |
22 |
23 | {% endfor %} 24 |
25 |
26 | 27 | {% for article in articles %} 28 |
29 | 32 |
33 |
34 | 35 |
36 | {{article.article_summary|safe}}... 37 |
38 |
39 |

40 | 喜欢({{article.article_sc}})   41 | 评论({{article.article_pl}})   42 | 浏览({{article.article_read_cnt}})   43 | {{article.article_date}}   44 | {{article.article_author}}   45 |

46 |
47 |
48 | {% endfor %} 49 | 50 |
    51 |
  • «
  • 52 | {% for article in articles[:5] %} 53 |
  • {{loop.index}}
  • 54 | {% endfor %} 55 |
  • »
  • 56 |

57 | 58 | 59 |
60 |
61 |
62 | 63 | {{super()}} 64 | {% endblock %} 65 | 66 | 67 | -------------------------------------------------------------------------------- /app/templates/login.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% import "bootstrap/wtf.html" as wtf %} 3 | {% block content%} 4 | 5 |
6 |
7 |
8 |
9 |
10 |

用户登录

11 | {{ wtf.quick_form(form) }} 12 |
13 |
14 |
15 |
16 |
17 | {% endblock content%} 18 | -------------------------------------------------------------------------------- /app/templates/login_in.html: -------------------------------------------------------------------------------- 1 | {% extends "base_login.html" %} 2 | 3 | 4 | {% block content %} 5 |
6 |
7 |
8 | 9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | 17 | 18 |
19 | 20 |
21 | 22 |
23 | 24 |
25 |
26 | 27 |
28 | 29 |
30 | 31 | {% for message in get_flashed_messages(with_categories=True) %} 32 |

{{ message[1] }}

33 | {% endfor %} 34 | 下次自动登录 35 |
36 |
37 | 38 |
39 |
40 | 41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | 50 | {% endblock content %} 51 | 52 | {% block scripts %} 53 | {{super()}} 54 | 55 | {% endblock %} 56 | -------------------------------------------------------------------------------- /app/templates/login_up.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% import "bootstrap/wtf.html" as wtf %} 3 | {% block content%} 4 | 5 |
6 |
7 |
8 |
9 |
10 |

用户注册

11 | {{ wtf.quick_form(form) }} 12 |
13 |
14 |
15 |
16 |
17 | {% endblock content%} 18 | -------------------------------------------------------------------------------- /app/templates/manage_article.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% block content %} 3 | 4 | 5 |
6 |
7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | {% for article in articles %} 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | {% endfor %} 29 | 30 |
标题发布状态评论数阅读数操作
{{article.article_title}} ({{article.article_date}})发布{{article.article_pl}}{{article.article_read_cnt}}删除
31 |
32 |
33 |
34 | 35 | {{super()}} 36 | {% endblock %} 37 | 38 | 39 | -------------------------------------------------------------------------------- /app/templates/manage_task.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% block content %} 3 | 4 | 5 |
6 |
7 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | {% for task in tasks %} 39 | 40 | 41 | {% if task.article_id %} 42 | 43 | {% else %} 44 | 45 | {% endif %} 46 | 47 | 48 | 49 | 56 | 59 | 60 | {% endfor %} 61 | 62 |
学习任务计划表
任务编号任务名称开始时间下次时间任务状态提醒类型操作标志
{{loop.index}}{{task.task_name}}{{task.task_name}}{{task.start_dt}}{{task.next_dt}}{{task.stat}} 50 | {% if task.remind == '1' %} 51 | 每日提醒 52 | {% else %} 53 | 曲线提醒 54 | {% endif %} 55 | 57 | 删除 58 |
63 |
64 |
65 |
66 | 67 | {{super()}} 68 | {% endblock %} 69 | 70 | 71 | -------------------------------------------------------------------------------- /app/templates/tools.html: -------------------------------------------------------------------------------- 1 | {% macro get_error(name) %} 2 | {% for error in form.{{name}}.errors %} 3 | {{error}} 4 | {% endfor %} 5 | {% endmacro %} -------------------------------------------------------------------------------- /app/templates/wrarticle.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | 3 | {% block content%} 4 |
5 |
6 |
7 |
8 |
9 | 10 | 11 |
12 |
13 |
14 | 15 | 16 |
17 |
18 |
19 |
20 | 21 | 24 | 27 |
28 |
29 | 30 | 33 | 36 |
37 |
38 | 39 | 40 |
41 |
42 | 43 |
44 |
45 |
46 | 47 | 48 | 49 | 50 | 51 | 62 | 72 | 73 | 74 | {{super()}} 75 | {% endblock %} 76 | -------------------------------------------------------------------------------- /app/tools.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Author: longzx 3 | # @Date: 2018-04-20 21:50:57 4 | # @cnblog:http://www.cnblogs.com/lonelyhiker/ 5 | 6 | import datetime 7 | from . import db 8 | from .models import Commparam 9 | 10 | 11 | def generate_id(param_name): 12 | # 序号产生器 13 | dt = str(datetime.date.today()).replace('-', '') 14 | commparam = Commparam.query.filter_by(param_name=param_name).first() 15 | 16 | # 如果不存在,就创建 17 | if commparam is None: 18 | # 创建参数对象 19 | commparam = Commparam(param_name=param_name) 20 | # 提交数据库 21 | db.session.add(commparam) 22 | num = 1 23 | else: 24 | commparam.param_value += 1 25 | num = commparam.param_value 26 | db.session.add(commparam) 27 | 28 | id = '%s%08d' % (dt, num) 29 | 30 | return id 31 | -------------------------------------------------------------------------------- /app/xiaoshuo/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longzx-9527/flask_spider/9a255ea83341437a94710097021564ca580c6ed6/app/xiaoshuo/__init__.py -------------------------------------------------------------------------------- /app/xiaoshuo/config.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Author: longzx 3 | # @Date: 2018-03-22 21:08:54 4 | 5 | import os 6 | from time import strftime 7 | 8 | # 用于存放数据 9 | BASE_PATH = os.path.join(os.getcwd(), 'data') 10 | # 日志文件 11 | LOG_FILE = os.path.join(BASE_PATH, 'xiaoshuo.log') 12 | # 用于存放爬取状态,可用于断点爬取 13 | LOG_STAT = os.path.join(BASE_PATH, 'spider_state.json') 14 | # 豆瓣电影分类文件 15 | MOVIES_TYPE_FILE = os.path.join(BASE_PATH, 'movies_type.csv') 16 | 17 | # 豆瓣电影网页 18 | main_url = 'https://movie.douban.com/chart' 19 | # 用于获取电影列表信息 20 | baseurl = 'https://movie.douban.com/j/chart/' 21 | # 获取豆瓣电影json数据类型 22 | top_list_type = ['top_list_count?', 'top_list?'] 23 | # 电影加载数 24 | MOVIE_LIMIT = 20 25 | 26 | # 日志文件 27 | LOG_DIR = os.path.join(BASE_PATH, 'log') 28 | LOGGER_FILE = os.path.join(LOG_DIR, 'info_{}.log'.format(strftime('%Y%m%d'))) 29 | LOGGER_ERROR_FILE = os.path.join(LOG_DIR, 'error_{}.log'.format( 30 | strftime('%Y%m%d'))) 31 | 32 | if not os.path.exists(BASE_PATH): 33 | os.mkdir(BASE_PATH) 34 | 35 | if not os.path.exists(LOG_DIR): 36 | os.mkdir(LOG_DIR) 37 | -------------------------------------------------------------------------------- /app/xiaoshuo/data/log/error_20180418.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/longzx-9527/flask_spider/9a255ea83341437a94710097021564ca580c6ed6/app/xiaoshuo/data/log/error_20180418.log -------------------------------------------------------------------------------- /app/xiaoshuo/data/log/info_20180418.log: -------------------------------------------------------------------------------- 1 | [2018-04-18 21:40:40,498 spider_tools.py:77] - main() >>>>>>>>>>>>>>>>>>> 2 | [2018-04-18 21:40:40,498 spider_tools.py:78] - main() 参数:('圣墟',) 3 | [2018-04-18 21:40:42,512 connectionpool.py:208] - Starting new HTTP connection (1): zhannei.baidu.com 4 | [2018-04-18 21:40:45,951 connectionpool.py:208] - Starting new HTTP connection (1): zhannei.baidu.com 5 | [2018-04-18 21:40:46,494 connectionpool.py:396] - http://zhannei.baidu.com:80 "GET /cse/search?s=920895234054625192&q=%E5%9C%A3%E5%A2%9F HTTP/1.1" 200 None 6 | [2018-04-18 21:40:46,623 sbcharsetprober.py:119] - MacCyrillic confidence = 0.021439632151179847, below negative shortcut threshhold 0.05 7 | [2018-04-18 21:40:46,749 charsetgroupprober.py:100] - utf-8 confidence = 0.99 8 | [2018-04-18 21:40:46,749 charsetgroupprober.py:100] - SHIFT_JIS Japanese confidence = 0.01 9 | [2018-04-18 21:40:46,750 charsetgroupprober.py:100] - EUC-JP Japanese confidence = 0.01 10 | [2018-04-18 21:40:46,750 charsetgroupprober.py:100] - GB2312 Chinese confidence = 0.01 11 | [2018-04-18 21:40:46,750 charsetgroupprober.py:100] - EUC-KR Korean confidence = 0.01 12 | [2018-04-18 21:40:46,750 charsetgroupprober.py:100] - CP949 Korean confidence = 0.01 13 | [2018-04-18 21:40:46,750 charsetgroupprober.py:100] - Big5 Chinese confidence = 0.01 14 | [2018-04-18 21:40:46,750 charsetgroupprober.py:100] - EUC-TW Taiwan confidence = 0.01 15 | [2018-04-18 21:40:46,750 charsetgroupprober.py:100] - windows-1251 Russian confidence = 0.01 16 | [2018-04-18 21:40:46,750 charsetgroupprober.py:100] - KOI8-R Russian confidence = 0.01 17 | [2018-04-18 21:40:46,750 charsetgroupprober.py:100] - ISO-8859-5 Russian confidence = 0.0007445414187372378 18 | [2018-04-18 21:40:46,750 charsetgroupprober.py:97] - MacCyrillic not active 19 | [2018-04-18 21:40:46,751 charsetgroupprober.py:100] - IBM866 Russian confidence = 0.07302596428307735 20 | [2018-04-18 21:40:46,751 charsetgroupprober.py:100] - IBM855 Russian confidence = 0.04381725215925389 21 | [2018-04-18 21:40:46,751 charsetgroupprober.py:100] - ISO-8859-7 Greek confidence = 0.0 22 | [2018-04-18 21:40:46,751 charsetgroupprober.py:100] - windows-1253 Greek confidence = 0.0 23 | [2018-04-18 21:40:46,751 charsetgroupprober.py:100] - ISO-8859-5 Bulgairan confidence = 0.0 24 | [2018-04-18 21:40:46,751 charsetgroupprober.py:100] - windows-1251 Bulgarian confidence = 0.0 25 | [2018-04-18 21:40:46,751 charsetgroupprober.py:100] - TIS-620 Thai confidence = 0.04498104067274472 26 | [2018-04-18 21:40:46,751 charsetgroupprober.py:100] - ISO-8859-9 Turkish confidence = 0.5056927849538179 27 | [2018-04-18 21:40:46,751 charsetgroupprober.py:100] - windows-1255 Hebrew confidence = 0.0 28 | [2018-04-18 21:40:46,751 charsetgroupprober.py:100] - windows-1255 Hebrew confidence = 0.0 29 | [2018-04-18 21:40:46,751 charsetgroupprober.py:100] - windows-1255 Hebrew confidence = 0.0 30 | [2018-04-18 21:40:46,751 charsetgroupprober.py:100] - utf-8 confidence = 0.99 31 | [2018-04-18 21:40:46,751 charsetgroupprober.py:100] - SHIFT_JIS Japanese confidence = 0.01 32 | [2018-04-18 21:40:46,751 charsetgroupprober.py:100] - EUC-JP Japanese confidence = 0.01 33 | [2018-04-18 21:40:46,752 charsetgroupprober.py:100] - GB2312 Chinese confidence = 0.01 34 | [2018-04-18 21:40:46,752 charsetgroupprober.py:100] - EUC-KR Korean confidence = 0.01 35 | [2018-04-18 21:40:46,752 charsetgroupprober.py:100] - CP949 Korean confidence = 0.01 36 | [2018-04-18 21:40:46,752 charsetgroupprober.py:100] - Big5 Chinese confidence = 0.01 37 | [2018-04-18 21:40:46,752 charsetgroupprober.py:100] - EUC-TW Taiwan confidence = 0.01 38 | [2018-04-18 21:40:48,838 connectionpool.py:208] - Starting new HTTP connection (1): www.qu.la 39 | [2018-04-18 21:40:49,706 connectionpool.py:396] - http://www.qu.la:80 "GET /book/24868/ HTTP/1.1" 301 152 40 | [2018-04-18 21:40:49,710 connectionpool.py:824] - Starting new HTTPS connection (1): www.qu.la 41 | [2018-04-18 21:40:51,212 connectionpool.py:396] - https://www.qu.la:443 "GET /book/24868/ HTTP/1.1" 200 148755 42 | [2018-04-18 21:40:53,513 sbcharsetprober.py:119] - ISO-8859-5 confidence = 0.0, below negative shortcut threshhold 0.05 43 | [2018-04-18 21:40:53,543 sbcharsetprober.py:119] - MacCyrillic confidence = 0.022522499270188366, below negative shortcut threshhold 0.05 44 | [2018-04-18 21:40:53,627 sbcharsetprober.py:119] - ISO-8859-7 confidence = 0.0, below negative shortcut threshhold 0.05 45 | [2018-04-18 21:40:53,648 sbcharsetprober.py:119] - windows-1253 confidence = 0.0, below negative shortcut threshhold 0.05 46 | [2018-04-18 21:40:53,674 sbcharsetprober.py:119] - ISO-8859-5 confidence = 0.0, below negative shortcut threshhold 0.05 47 | [2018-04-18 21:40:53,697 sbcharsetprober.py:119] - windows-1251 confidence = 0.0, below negative shortcut threshhold 0.05 48 | [2018-04-18 21:40:53,723 sbcharsetprober.py:119] - TIS-620 confidence = 0.02088918509058682, below negative shortcut threshhold 0.05 49 | [2018-04-18 21:40:53,816 sbcharsetprober.py:119] - windows-1255 confidence = 0.0, below negative shortcut threshhold 0.05 50 | [2018-04-18 21:40:53,839 sbcharsetprober.py:119] - windows-1255 confidence = 0.0, below negative shortcut threshhold 0.05 51 | [2018-04-18 21:40:53,919 charsetgroupprober.py:100] - utf-8 confidence = 0.99 52 | [2018-04-18 21:40:53,920 charsetgroupprober.py:100] - SHIFT_JIS Japanese confidence = 0.01 53 | [2018-04-18 21:40:53,920 charsetgroupprober.py:100] - EUC-JP Japanese confidence = 0.01 54 | [2018-04-18 21:40:53,920 charsetgroupprober.py:100] - GB2312 Chinese confidence = 0.01 55 | [2018-04-18 21:40:53,920 charsetgroupprober.py:100] - EUC-KR Korean confidence = 0.01 56 | [2018-04-18 21:40:53,920 charsetgroupprober.py:100] - CP949 Korean confidence = 0.01 57 | [2018-04-18 21:40:53,920 charsetgroupprober.py:100] - Big5 Chinese confidence = 0.01 58 | [2018-04-18 21:40:53,920 charsetgroupprober.py:100] - EUC-TW Taiwan confidence = 0.01 59 | [2018-04-18 21:40:53,920 charsetgroupprober.py:100] - windows-1251 Russian confidence = 0.01 60 | [2018-04-18 21:40:53,920 charsetgroupprober.py:100] - KOI8-R Russian confidence = 0.01 61 | [2018-04-18 21:40:53,920 charsetgroupprober.py:97] - ISO-8859-5 not active 62 | [2018-04-18 21:40:53,920 charsetgroupprober.py:97] - MacCyrillic not active 63 | [2018-04-18 21:40:53,920 charsetgroupprober.py:100] - IBM866 Russian confidence = 0.08318697543076992 64 | [2018-04-18 21:40:53,920 charsetgroupprober.py:100] - IBM855 Russian confidence = 0.07269156500208435 65 | [2018-04-18 21:40:53,920 charsetgroupprober.py:97] - ISO-8859-7 not active 66 | [2018-04-18 21:40:53,920 charsetgroupprober.py:97] - windows-1253 not active 67 | [2018-04-18 21:40:53,920 charsetgroupprober.py:97] - ISO-8859-5 not active 68 | [2018-04-18 21:40:53,920 charsetgroupprober.py:97] - windows-1251 not active 69 | [2018-04-18 21:40:53,920 charsetgroupprober.py:97] - TIS-620 not active 70 | [2018-04-18 21:40:53,920 charsetgroupprober.py:100] - ISO-8859-9 Turkish confidence = 0.26587781792750725 71 | [2018-04-18 21:40:53,920 charsetgroupprober.py:100] - windows-1255 Hebrew confidence = 0.0 72 | [2018-04-18 21:40:53,921 charsetgroupprober.py:97] - windows-1255 not active 73 | [2018-04-18 21:40:53,921 charsetgroupprober.py:97] - windows-1255 not active 74 | [2018-04-18 21:40:53,921 charsetgroupprober.py:100] - utf-8 confidence = 0.99 75 | [2018-04-18 21:40:53,921 charsetgroupprober.py:100] - SHIFT_JIS Japanese confidence = 0.01 76 | [2018-04-18 21:40:53,921 charsetgroupprober.py:100] - EUC-JP Japanese confidence = 0.01 77 | [2018-04-18 21:40:53,921 charsetgroupprober.py:100] - GB2312 Chinese confidence = 0.01 78 | [2018-04-18 21:40:53,921 charsetgroupprober.py:100] - EUC-KR Korean confidence = 0.01 79 | [2018-04-18 21:40:53,921 charsetgroupprober.py:100] - CP949 Korean confidence = 0.01 80 | [2018-04-18 21:40:53,921 charsetgroupprober.py:100] - Big5 Chinese confidence = 0.01 81 | [2018-04-18 21:40:53,921 charsetgroupprober.py:100] - EUC-TW Taiwan confidence = 0.01 82 | [2018-04-18 21:41:03,118 connectionpool.py:208] - Starting new HTTP connection (1): www.qu.la 83 | [2018-04-18 21:41:03,960 connectionpool.py:396] - http://www.qu.la:80 "GET /book/24868/10664976.html HTTP/1.1" 301 165 84 | [2018-04-18 21:41:03,965 connectionpool.py:824] - Starting new HTTPS connection (1): www.qu.la 85 | -------------------------------------------------------------------------------- /app/xiaoshuo/mylogger.py: -------------------------------------------------------------------------------- 1 | import logging 2 | import logging.handlers 3 | from .config import LOGGER_FILE, LOGGER_ERROR_FILE 4 | 5 | 6 | # 获取日志器 7 | def init_logging(verbose=1, logger_name=None): 8 | """ 9 | 1.获取日志器 10 | 2.设置日志级别 11 | 3.获取处理器 12 | 4.设置处理器级别 13 | 5.文件打印格式 14 | 6.添加处理器到日志器 15 | """ 16 | formatter = logging.Formatter( 17 | ("[%(asctime)s %(filename)s:%(lineno)s] - %(message)s ")) 18 | 19 | logger = logging.getLogger(logger_name) 20 | logger.setLevel(logging.DEBUG if verbose > 0 else logging.INFO) 21 | 22 | rf_handler = logging.handlers.TimedRotatingFileHandler( 23 | LOGGER_FILE, encoding='utf-8') 24 | rf_handler.setFormatter(formatter) 25 | 26 | f_handler = logging.FileHandler(LOGGER_ERROR_FILE, encoding='utf-8') 27 | f_handler.setLevel(logging.ERROR) 28 | f_handler.setFormatter(formatter) 29 | 30 | logger.addHandler(rf_handler) 31 | logger.addHandler(f_handler) 32 | 33 | return logger 34 | 35 | 36 | logger = init_logging() 37 | -------------------------------------------------------------------------------- /app/xiaoshuo/spider_tools.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Author: longzx 3 | # @Date: 2018-03-08 20:56:26 4 | """ 5 | 爬虫常用工具包 6 | 将一些通用的功能进行封装 7 | """ 8 | from functools import wraps 9 | from random import choice, randint 10 | from time import ctime, sleep, time 11 | 12 | import pymysql 13 | import requests 14 | from requests.exceptions import RequestException 15 | from app.models import Fiction, Fiction_Content, Fiction_Lst 16 | from app import db 17 | 18 | #请求头 19 | headers = {} 20 | headers[ 21 | 'Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' 22 | headers['Accept-Encoding'] = 'gzip, deflate, br' 23 | headers['Accept-Language'] = 'zh-CN,zh;q=0.9' 24 | headers['Connection'] = 'keep-alive' 25 | headers['Upgrade-Insecure-Requests'] = '1' 26 | 27 | agents = [ 28 | "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36", 29 | "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1", 30 | "Mozilla/5.0 (X11; CrOS i686 2268.111.0) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11", 31 | "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1092.0 Safari/536.6", 32 | "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1090.0 Safari/536.6", 33 | "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/19.77.34.5 Safari/537.1", 34 | "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.9 Safari/536.5", 35 | "Mozilla/5.0 (Windows NT 6.0) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.36 Safari/536.5", 36 | "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1063.0 Safari/536.3", 37 | "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1063.0 Safari/536.3", 38 | "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_0) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1063.0 Safari/536.3", 39 | "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1062.0 Safari/536.3", 40 | "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1062.0 Safari/536.3", 41 | "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1061.1 Safari/536.3", 42 | "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1061.1 Safari/536.3", 43 | "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1061.1 Safari/536.3", 44 | "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1061.0 Safari/536.3", 45 | "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.24 (KHTML, like Gecko) Chrome/19.0.1055.1 Safari/535.24", 46 | "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/535.24 (KHTML, like Gecko) Chrome/19.0.1055.1 Safari/535.24", 47 | 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36' 48 | ] 49 | 50 | 51 | def get_one_page(url, proxies=None, sflag=1): 52 | #获取给定的url页面 53 | while True: 54 | try: 55 | headers['User-Agent'] = choice(agents) 56 | # 控制爬取速度 57 | if sflag: 58 | print('放慢下载速度。。。。。。') 59 | sleep(randint(1, 3)) 60 | 61 | print('正在下载:', url) 62 | if proxies: 63 | r = requests.get( 64 | url, headers=headers, timeout=5, proxies=proxies) 65 | else: 66 | r = requests.get(url, headers=headers, timeout=5) 67 | 68 | except Exception as r: 69 | print('errorinfo:', r) 70 | continue 71 | else: 72 | if r.status_code == 200: 73 | r.encoding = r.apparent_encoding 74 | print('爬取成功!!!') 75 | return r.text 76 | else: 77 | continue 78 | 79 | 80 | def insert_fiction(fiction_name, fiction_id, fiction_real_url, fiction_img, 81 | fiction_author, fiction_comment): 82 | fiction = Fiction().query.filter_by(fiction_id=fiction_id).first() 83 | if fiction is None: 84 | fiction = Fiction( 85 | fiction_name=fiction_name, 86 | fiction_id=fiction_id, 87 | fiction_real_url=fiction_real_url, 88 | fiction_img=fiction_img, 89 | fiction_author=fiction_author, 90 | fiction_comment=fiction_comment) 91 | db.session.add(fiction) 92 | db.session.commit() 93 | else: 94 | print('记录已存在,无需下载') 95 | 96 | 97 | def insert_fiction_lst(fiction_name, fiction_id, fiction_lst_url, 98 | fiction_lst_name, fiction_real_url): 99 | fl = Fiction_Lst().query.filter_by( 100 | fiction_id=fiction_id, fiction_lst_url=fiction_lst_url).first() 101 | if fl is None: 102 | fl = Fiction_Lst( 103 | fiction_name=fiction_name, 104 | fiction_id=fiction_id, 105 | fiction_lst_url=fiction_lst_url, 106 | fiction_lst_name=fiction_lst_name, 107 | fiction_real_url=fiction_real_url) 108 | db.session.add(fl) 109 | db.session.commit() 110 | 111 | 112 | def insert_fiction_content(fiction_url, fiction_content, fiction_id): 113 | fc = Fiction_Content( 114 | fiction_id=fiction_id, 115 | fiction_content=fiction_content, 116 | fiction_url=fiction_url) 117 | db.session.add(fc) 118 | db.session.commit() 119 | 120 | 121 | def update_fiction(fiction_id, update_time, new_content, new_url): 122 | fiction = Fiction().query.filter_by(fiction_id=fiction_id).first() 123 | fiction.update = update_time 124 | fiction.new_content = new_content 125 | fiction.new_url = new_url 126 | db.session.add(fiction) 127 | db.session.commit() 128 | -------------------------------------------------------------------------------- /app/xiaoshuo/xiaoshuoSpider.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Author: longzx 3 | # @Date: 2018-03-10 21:41:55 4 | # @cnblog:http://www.cnblogs.com/lonelyhiker/ 5 | 6 | import requests 7 | import sys 8 | from bs4 import BeautifulSoup 9 | from pymysql.err import ProgrammingError 10 | from app.xiaoshuo.spider_tools import get_one_page, update_fiction, insert_fiction, insert_fiction_content, insert_fiction_lst 11 | from app.models import Fiction_Lst, Fiction_Content, Fiction 12 | 13 | 14 | def search_fiction(name, flag=1): 15 | """输入小说名字 16 | 17 | 返回小说在网站的具体网址 18 | """ 19 | if name is None: 20 | raise Exception('小说名字必须输入!!!') 21 | 22 | url = 'http://zhannei.baidu.com/cse/search?s=920895234054625192&q={}'.format( 23 | name) 24 | 25 | html = get_one_page(url, sflag=flag) 26 | soup = BeautifulSoup(html, 'html5lib') 27 | result_list = soup.find('div', 'result-list') 28 | fiction_lst = result_list.find_all('a', 'result-game-item-title-link') 29 | fiction_url = fiction_lst[0].get('href') 30 | fiction_name = fiction_lst[0].text.strip() 31 | fiction_img = soup.find('img')['src'] 32 | fiction_comment = soup.find_all('p', 'result-game-item-desc')[0].text 33 | fiction_author = soup.find_all( 34 | 'div', 'result-game-item-info')[0].find_all('span')[1].text.strip() 35 | 36 | if fiction_name is None: 37 | print('{} 小说不存在!!!'.format(name)) 38 | raise Exception('{} 小说不存在!!!'.format(name)) 39 | 40 | fictions = (fiction_name, fiction_url, fiction_img, fiction_author, 41 | fiction_comment) 42 | save_fiction_url(fictions) 43 | 44 | return fiction_name, fiction_url 45 | 46 | 47 | def get_fiction_list(fiction_name, fiction_url, flag=1): 48 | # 获取小说列表 49 | fiction_html = get_one_page(fiction_url, sflag=flag) 50 | soup = BeautifulSoup(fiction_html, 'html5lib') 51 | dd_lst = soup.find_all('dd') 52 | updatetime = str(soup.find(id='info').find_all('p')[-2]).strip('

/') 53 | new_content = soup.find(id="info").find_all('p')[-1].a.text 54 | fiction_id = fiction_url.split('/')[-2] 55 | new_url = soup.find(id="info").find_all('p')[-1].a['href'].strip('.html') 56 | # 更新最新章节 57 | update_fiction( 58 | fiction_id=fiction_id, 59 | update_time=updatetime, 60 | new_content=new_content, 61 | new_url=new_url) 62 | 63 | fiction_lst = [] 64 | for item in dd_lst[12:]: 65 | fiction_lst_name = item.a.text.strip() 66 | fiction_lst_url = item.a['href'].split('/')[-1].strip('.html') 67 | fiction_real_url = fiction_url + fiction_lst_url + '.html' 68 | lst = (fiction_name, fiction_id, fiction_lst_url, fiction_lst_name, 69 | fiction_real_url) 70 | fiction_lst.append(lst) 71 | return fiction_lst 72 | 73 | 74 | def get_fiction_content(fiction_url, flag=1): 75 | fiction_id = fiction_url.split('/')[-2] 76 | fiction_conntenturl = fiction_url.split('/')[-1].strip('.html') 77 | fc = Fiction_Content().query.filter_by( 78 | fiction_id=fiction_id, fiction_url=fiction_url).first() 79 | if fc is None: 80 | print('此章节不存在,需下载') 81 | html = get_one_page(fiction_url, sflag=flag) 82 | soup = BeautifulSoup(html, 'html5lib') 83 | content = soup.find(id='content') 84 | f_content = str(content) 85 | save_fiction_content(fiction_url, f_content) 86 | else: 87 | print('此章节已存在,无需下载!!!') 88 | 89 | 90 | def save_fiction_url(fictions): 91 | args = (fictions[0], fictions[1].split('/')[-2], fictions[1], fictions[2], 92 | fictions[3], fictions[4]) 93 | insert_fiction(*args) 94 | 95 | 96 | def save_fiction_lst(fiction_lst): 97 | total = len(fiction_lst) 98 | if Fiction().query.filter_by(fiction_id=fiction_lst[0][1]) == total: 99 | print('此小说已存在!!,无需下载') 100 | return 1 101 | for item in fiction_lst: 102 | insert_fiction_lst(*item) 103 | 104 | 105 | def save_fiction_content(fiction_url, fiction_content): 106 | fiction_id = fiction_url.split('/')[-2] 107 | fiction_conntenturl = fiction_url.split('/')[-1].strip('.html') 108 | insert_fiction_content(fiction_conntenturl, fiction_content, fiction_id) 109 | 110 | 111 | def down_fiction_lst(f_name): 112 | # 1.搜索小说 113 | args = search_fiction(f_name, flag=0) 114 | # 2.获取小说目录列表 115 | fiction_lst = get_fiction_list(*args, flag=0) 116 | # 3.保存小说目录列表 117 | flag = save_fiction_lst(fiction_lst) 118 | print('下载小说列表完成!!') 119 | 120 | 121 | def down_fiction_content(f_url): 122 | get_fiction_content(f_url, flag=0) 123 | print('下载章节完成!!') 124 | 125 | 126 | def update_fiction_lst(f_name, f_url): 127 | # 1.获取小说目录列表 128 | fiction_lst = get_fiction_list( 129 | fiction_name=f_name, fiction_url=f_url, flag=0) 130 | # 2.保存小说目录列表 131 | flag = save_fiction_lst(fiction_lst) 132 | print('更新小说列表完成!!') 133 | -------------------------------------------------------------------------------- /blog.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat MySQL Data Transfer 3 | 4 | Source Server : mysql 5 | Source Server Version : 50721 6 | Source Host : 192.168.66.188:3306 7 | Source Database : blog 8 | 9 | Target Server Type : MYSQL 10 | Target Server Version : 50721 11 | File Encoding : 65001 12 | 13 | Date: 2018-04-25 08:39:14 14 | */ 15 | 16 | SET FOREIGN_KEY_CHECKS=0; 17 | 18 | -- ---------------------------- 19 | -- Table structure for alembic_version 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `alembic_version`; 22 | CREATE TABLE `alembic_version` ( 23 | `version_num` varchar(32) NOT NULL, 24 | PRIMARY KEY (`version_num`) 25 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 26 | 27 | -- ---------------------------- 28 | -- Table structure for article 29 | -- ---------------------------- 30 | DROP TABLE IF EXISTS `article`; 31 | CREATE TABLE `article` ( 32 | `article_id` varchar(20) NOT NULL, 33 | `article_title` varchar(100) NOT NULL, 34 | `article_text` text, 35 | `article_summary` varchar(255) DEFAULT NULL, 36 | `article_read_cnt` int(11) DEFAULT NULL, 37 | `article_sc` int(11) DEFAULT NULL, 38 | `article_pl` int(11) DEFAULT NULL, 39 | `article_date` datetime DEFAULT NULL, 40 | `article_url` text, 41 | `article_type` varchar(10) DEFAULT NULL, 42 | `article_author` varchar(20) DEFAULT NULL, 43 | `user_id` varchar(20) DEFAULT NULL, 44 | PRIMARY KEY (`article_id`) 45 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 46 | 47 | -- ---------------------------- 48 | -- Table structure for comment 49 | -- ---------------------------- 50 | DROP TABLE IF EXISTS `comment`; 51 | CREATE TABLE `comment` ( 52 | `comment_id` varchar(20) NOT NULL, 53 | `comment_text` text, 54 | `comment_date` datetime DEFAULT NULL, 55 | `user_id` varchar(20) NOT NULL, 56 | `article_id` varchar(20) NOT NULL, 57 | PRIMARY KEY (`comment_id`) 58 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 59 | 60 | -- ---------------------------- 61 | -- Table structure for commparam 62 | -- ---------------------------- 63 | DROP TABLE IF EXISTS `commparam`; 64 | CREATE TABLE `commparam` ( 65 | `param_name` varchar(10) NOT NULL, 66 | `param_value` int(11) DEFAULT NULL, 67 | `param_text` varchar(100) DEFAULT NULL, 68 | `param_stat` varchar(2) DEFAULT NULL, 69 | PRIMARY KEY (`param_name`) 70 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 71 | 72 | -- ---------------------------- 73 | -- Table structure for fiction 74 | -- ---------------------------- 75 | DROP TABLE IF EXISTS `fiction`; 76 | CREATE TABLE `fiction` ( 77 | `id` int(11) NOT NULL AUTO_INCREMENT, 78 | `fiction_name` varchar(255) DEFAULT NULL, 79 | `fiction_id` varchar(255) DEFAULT NULL, 80 | `fiction_real_url` varchar(255) DEFAULT NULL, 81 | `fiction_img` varchar(255) DEFAULT NULL, 82 | `fiction_author` char(30) DEFAULT NULL, 83 | `fiction_comment` varchar(255) DEFAULT NULL, 84 | `update` varchar(255) DEFAULT NULL, 85 | `new_content` varchar(255) DEFAULT NULL, 86 | `new_url` varchar(255) DEFAULT NULL, 87 | PRIMARY KEY (`id`) 88 | ) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8; 89 | 90 | -- ---------------------------- 91 | -- Table structure for fiction_content 92 | -- ---------------------------- 93 | DROP TABLE IF EXISTS `fiction_content`; 94 | CREATE TABLE `fiction_content` ( 95 | `id` int(11) NOT NULL AUTO_INCREMENT, 96 | `fiction_url` varchar(255) DEFAULT NULL, 97 | `fiction_content` longtext, 98 | `fiction_id` int(11) DEFAULT NULL, 99 | PRIMARY KEY (`id`) 100 | ) ENGINE=InnoDB AUTO_INCREMENT=3274 DEFAULT CHARSET=utf8; 101 | 102 | -- ---------------------------- 103 | -- Table structure for fiction_lst 104 | -- ---------------------------- 105 | DROP TABLE IF EXISTS `fiction_lst`; 106 | CREATE TABLE `fiction_lst` ( 107 | `id` int(11) NOT NULL AUTO_INCREMENT, 108 | `fiction_name` varchar(255) DEFAULT NULL, 109 | `fiction_id` varchar(255) DEFAULT NULL, 110 | `fiction_lst_url` varchar(255) DEFAULT NULL, 111 | `fiction_lst_name` varchar(255) DEFAULT NULL, 112 | `fiction_real_url` varchar(255) DEFAULT NULL, 113 | PRIMARY KEY (`id`) 114 | ) ENGINE=InnoDB AUTO_INCREMENT=7646 DEFAULT CHARSET=utf8; 115 | 116 | -- ---------------------------- 117 | -- Table structure for user 118 | -- ---------------------------- 119 | DROP TABLE IF EXISTS `user`; 120 | CREATE TABLE `user` ( 121 | `user_id` varchar(20) NOT NULL, 122 | `user_name` varchar(30) DEFAULT NULL, 123 | `nickname` varchar(40) DEFAULT NULL, 124 | `sex` varchar(4) DEFAULT NULL, 125 | `age` int(11) DEFAULT NULL, 126 | `password_hash` varchar(128) DEFAULT NULL, 127 | `email` varchar(50) DEFAULT NULL, 128 | `last_login_tm` datetime DEFAULT NULL, 129 | `user_crt_dt` datetime DEFAULT NULL, 130 | `attention_cnt` int(11) DEFAULT NULL, 131 | PRIMARY KEY (`user_id`), 132 | UNIQUE KEY `email` (`email`), 133 | UNIQUE KEY `nickname` (`nickname`), 134 | UNIQUE KEY `user_name` (`user_name`) 135 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 136 | -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Author: longzx 3 | # @Date: 2018-04-14 11:42:41 4 | # @cnblog:http://www.cnblogs.com/lonelyhiker/ 5 | 6 | import os 7 | 8 | from time import strftime 9 | import logging 10 | 11 | log_name = os.path.join( 12 | os.getenv('HOME'), 'log/flask/log_{}.log'.format(strftime('%Y%m%d'))) 13 | 14 | FLASK_LOG_FILE = os.getenv('FLASK_LOG_FILE') or log_name 15 | 16 | if not os.path.exists(os.path.dirname(FLASK_LOG_FILE)): 17 | os.makedirs(os.path.dirname(FLASK_LOG_FILE)) 18 | 19 | 20 | def get_handler(): 21 | 22 | # 获取处理器 23 | f_handler = logging.FileHandler(FLASK_LOG_FILE, encoding='utf-8') 24 | formatter = logging.Formatter( 25 | '[%(asctime)s %(filename)s:%(lineno)s] - %(message)s') 26 | f_handler.setFormatter(formatter) 27 | f_handler.setLevel(logging.DEBUG) 28 | 29 | return f_handler 30 | 31 | 32 | basedir = os.path.abspath(os.path.dirname(__file__)) 33 | 34 | 35 | class Config: 36 | """默认配置 主要是对数据库进行相关配置 37 | 对象关系映射(Object Relational Mapping,简称ORM)是通过使用描述对象和数据库之间映射的元数据, 38 | 将面向对象语言程序中的对象自动持久化到关系数据库中。 39 | 这样,我们在具体的操作业务对象的时候,就不需要再去和复杂的SQL语句打交道,只要像平时操作对象一样操作它就可以了。 40 |   ORM框架就是用于实现ORM技术的程序。 41 | 42 | SQLAlchemy是Python编程语言下的一款开源软件。提供了SQL工具包及对象关系映射(ORM)工具,使用MIT许可证发行。 43 | 44 | SQLAlchmey采用了类似于Java里Hibernate的数据映射模型, 45 | """ 46 | FLATPAGES_AUTO_RELOAD = True 47 | FLATPAGES_EXTENSION = '.md' 48 | SECRET_KEY = os.environ.get('SECRET_KEY') or 'can you guess it' 49 | DEBUG = True 50 | # sqlalchemy两个主要配置 51 | # ORM底层所访问数据库URI 52 | SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://lzx:123@192.168.66.188/blog?charset=utf8' 53 | # 当关闭数据库是否自动提交事务 54 | SQLALCHEMY_COMMIT_ON_TEARDOWN = True 55 | # 是否追踪修改 56 | SQLALCHEMY_TRACK_MODIFICATIONS = True 57 | 58 | @staticmethod 59 | def init_app(app): 60 | # app.logger.setLevel(logging.DEBUG) 61 | # app.logger.addHandler(get_handler) 62 | pass 63 | 64 | 65 | class DevelopmentConfig(Config): 66 | """开发环境配置 67 | """ 68 | 69 | #可以通过修改SQLALCHEMY_DATABASE_URI来控制访问不同数据库 70 | SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://lzx:123@192.168.66.188/blog?charset=utf8' 71 | 72 | 73 | class TestConfig(Config): 74 | """测试环境配置 75 | """ 76 | 77 | #可以通过修改SQLALCHEMY_DATABASE_URI来控制访问不同数据库 78 | SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://lzx:123@192.168.66.188/blog?charset=utf8' 79 | 80 | 81 | class ProductionConfig(Config): 82 | """生产环境 83 | """ 84 | #可以通过修改SQLALCHEMY_DATABASE_URI来控制访问不同数据库 85 | SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://lzx:123@192.168.66.188/blog' 86 | 87 | 88 | # 设置配置映射 89 | config = { 90 | 'production': ProductionConfig, 91 | 'development': DevelopmentConfig, 92 | 'test': TestConfig, 93 | 'default': DevelopmentConfig 94 | } 95 | -------------------------------------------------------------------------------- /manage.py: -------------------------------------------------------------------------------- 1 | import os 2 | from app import create_app, db 3 | from flask_script import Manager, Shell 4 | from flask_migrate import Migrate, MigrateCommand 5 | import app.models 6 | 7 | app = create_app(os.getenv('FLASK_CONFIG') or 'default') 8 | manager = Manager(app) 9 | migrate = Migrate(app, db) 10 | 11 | 12 | def make_shell_context(): 13 | return dict(app=app, db=db) 14 | 15 | 16 | manager.add_command("shell", Shell(make_context=make_shell_context)) 17 | manager.add_command('db', MigrateCommand) 18 | 19 | if __name__ == '__main__': 20 | manager.run() 21 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | alembic==0.9.8 2 | aniso8601==3.0.0 3 | astroid==1.6.3 4 | beautifulsoup4==4.6.0 5 | blinker==1.4 6 | bs4==0.0.1 7 | certifi==2018.1.18 8 | chardet==3.0.4 9 | click==6.7 10 | decorator==4.2.1 11 | dominate==2.3.1 12 | Flask==0.12.2 13 | Flask-Bootstrap==3.3.7.1 14 | Flask-Failsafe==0.2 15 | Flask-FlatPages==0.6 16 | Flask-HTTPAuth==3.2.3 17 | Flask-Login==0.4.1 18 | Flask-Mail==0.9.1 19 | Flask-Markdown==0.3 20 | Flask-Migrate==2.1.1 21 | Flask-RESTful==0.3.6 22 | Flask-Script==2.0.6 23 | Flask-SQLAlchemy==2.3.2 24 | Flask-WTF==0.14.2 25 | gevent==1.2.2 26 | greenlet==0.4.13 27 | gunicorn==19.7.1 28 | html5lib==1.0.1 29 | idna==2.6 30 | ipython==6.2.1 31 | ipython-genutils==0.2.0 32 | isort==4.3.4 33 | itsdangerous==0.24 34 | jedi==0.11.1 35 | Jinja2==2.10 36 | lazy-object-proxy==1.3.1 37 | lxml==4.2.1 38 | Mako==1.0.7 39 | Markdown==2.6.11 40 | markdown2==2.3.5 41 | MarkupSafe==1.0 42 | mccabe==0.6.1 43 | parso==0.1.1 44 | pexpect==4.4.0 45 | pickleshare==0.7.4 46 | prompt-toolkit==1.0.15 47 | ptyprocess==0.5.2 48 | pudb==2017.1.4 49 | Pygments==2.2.0 50 | pylint==1.8.4 51 | PyMySQL==0.8.0 52 | python-dateutil==2.6.1 53 | python-editor==1.0.3 54 | pytz==2018.4 55 | PyYAML==3.12 56 | redis==2.10.6 57 | requests==2.18.4 58 | simplegeneric==0.8.1 59 | six==1.11.0 60 | SQLAlchemy==1.2.7 61 | traitlets==4.3.2 62 | urllib3==1.22 63 | urwid==2.0.1 64 | visitor==0.1.3 65 | wcwidth==0.1.7 66 | webencodings==0.5.1 67 | Werkzeug==0.14.1 68 | wrapt==1.10.11 69 | WTForms==2.1 70 | -------------------------------------------------------------------------------- /sendemail.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Author: longzx 3 | # @Date: 2018-05-11 22:31:54 4 | # @cnblog:http://www.cnblogs.com/lonelyhiker/ 5 | 6 | import os 7 | import contextlib 8 | import configparser 9 | import smtplib 10 | import pymysql 11 | from datetime import timedelta, datetime 12 | from email.header import Header 13 | from email.mime.text import MIMEText 14 | """ 15 | 发送定时任务,到指定邮箱 16 | """ 17 | cf = configparser.ConfigParser() 18 | cf.read('/home/longzx/etc/config.ini') 19 | print(cf.sections()) 20 | 21 | 22 | def sendEmail(content=None, title=None, receivers=None): 23 | mail_host = cf.get('MAIL', 'mail_host') 24 | mail_user = cf.get('MAIL', 'mail_user') 25 | mail_pass = cf.get('MAIL', 'mail_pass') 26 | sender = mail_user 27 | print('user={} pass={}'.format(mail_user, mail_pass)) 28 | try: 29 | smtpObj = smtplib.SMTP_SSL(mail_host, 465) # 启用SSL发信, 端口一般是465 30 | smtpObj.login(mail_user, mail_pass) 31 | for i in range(len(title)): 32 | message = MIMEText(content[i], 'html', 'utf-8') # 内容, 格式, 编码 33 | message['From'] = "{}".format(sender) 34 | message['To'] = ",".join(receivers) 35 | message['Subject'] = title[i] 36 | smtpObj.sendmail(sender, receivers, message.as_string()) 37 | 38 | smtpObj.close() 39 | print("mail has been send successfully.") 40 | except smtplib.SMTPException as e: 41 | print(e) 42 | 43 | 44 | def get_next_dt(begin_dt=None, stage=1): 45 | print(begin_dt) 46 | if stage == 1: 47 | return begin_dt + timedelta(days=1) 48 | if stage == 2: 49 | return begin_dt + timedelta(days=2) 50 | if stage == 3: 51 | return begin_dt + timedelta(days=4) 52 | if stage == 4: 53 | return begin_dt + timedelta(days=7) 54 | if stage == 5: 55 | return begin_dt + timedelta(day=14) 56 | return False 57 | 58 | 59 | #定义上下文管理器,连接后自动关闭连接 60 | @contextlib.contextmanager 61 | def mysql( 62 | host=cf.get("DATABASE", 'host'), 63 | port=cf.getint('DATABASE', 'port'), 64 | user=cf.get('DATABASE', 'user'), 65 | passwd=cf.get('DATABASE', 'passwd'), 66 | db=cf.get('DATABASE', 'db'), 67 | charset=cf.get('DATABASE', 'charset')): 68 | conn = pymysql.connect( 69 | host=host, port=port, user=user, passwd=passwd, db=db, charset=charset) 70 | cursor = conn.cursor(cursor=pymysql.cursors.DictCursor) 71 | try: 72 | yield cursor 73 | finally: 74 | conn.commit() 75 | cursor.close() 76 | conn.close() 77 | 78 | 79 | if __name__ == '__main__': 80 | with mysql() as cursor: 81 | now_dt = datetime.now().date() 82 | cnt = cursor.execute( 83 | "select * from task where next_dt =%s or remind='1' ", str(now_dt)) 84 | results = cursor.fetchall() 85 | content = [] 86 | title = [] 87 | for task in results: 88 | next_dt = datetime.strptime(task.get('next_dt'), '%Y-%m-%d') 89 | if task.get('remind') == '1': 90 | content.append(task.get('content')) 91 | title.append(task.get('task_name')) 92 | elif now_dt == next_dt.date(): 93 | next_dt = get_next_dt(next_dt, stage=task.get('stage') + 1) 94 | print('next_dt', next_dt) 95 | if next_dt == False: 96 | continue 97 | else: 98 | next_dt = str(next_dt.date()) 99 | cursor.execute( 100 | "update task set next_dt='%s',stage=%d where task_id='%s' " 101 | % (next_dt, task.get('stage') + 1, task.get('task_id'))) 102 | content.append(task.get('content')) 103 | title.append(task.get('task_name')) 104 | 105 | if cnt > 0: 106 | receivers = ['904185259@qq.com', 'longzongxing@dingtalk.com'] 107 | sendEmail(content, title, receivers) 108 | -------------------------------------------------------------------------------- /start.sh: -------------------------------------------------------------------------------- 1 | gunicorn -w 3 -k gevent wsgi -b 0.0.0.0:80 2 | #python manage.py runserver -h 0.0.0.0 -p 5000 3 | 4 | -------------------------------------------------------------------------------- /stop.sh: -------------------------------------------------------------------------------- 1 | ps -ef|grep -v grep |grep runserver|awk '{print }'|xargs kill -9 2 | -------------------------------------------------------------------------------- /wsgi.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # @Author: longzx 3 | # @Date: 2018-04-22 15:54:36 4 | # @cnblog:http://www.cnblogs.com/lonelyhiker/ 5 | 6 | from app import create_app 7 | 8 | application = app = create_app('default') 9 | --------------------------------------------------------------------------------