huanshuai
huanshuai
Reputation Top 1%
Li Huanshuai
8 Snippets  (108th place)
Published
1 Channel
Created
22 Channels
Following
569 points  (61st place)
Reputation
Junior Code Generator
Serious Code Generator
Senior Code Generator
Junior Publisher
Serious Publisher
Junior Trend Maker
Junior Judge
Junior Popular Coder
Serious Popular Coder
Junior Autobiographer
Senior Autobiographer
Junior Famous Coder
Serious Famous Coder
Junior Wise Coder

Recent Snippets See all snippets by huanshuai

public by huanshuai  1882  0  5  0

logging.conf

[loggers]
keys=root,main

[handlers]
keys=consoleHandler,fileHandler

[formatters]
keys=fmt

[logger_root]
level=DEBUG
handlers=consoleHandler

[logger_main]
level=DEBUG
qualname=main
handlers=fileHandler

[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=fmt
args=(sys.stdout,)

[handler_fileHandler]
class=logging.handlers.RotatingFileHandler
level=DEBUG
formatter=fmt
args=('tst.log','a',20000,5,)

[formatter_fmt]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
datefmt=
                        
;

public by huanshuai  2724  2  5  0

Makefile for Python App

VENV=./venv
PYTHON=$(VENV)/bin/python
PIP=$(VENV)/bin/pip
 
PACKAGE=rtlogclient
SETUP=./setup.py
REQUIREMENTS=./requirements.txt
TEST_DIR=./tests/
 
.PHONY: all update_tools install_requirements install develop test
 
usage:
	@echo use `make [target]` to build project.
 
update_tools:
	$(PIP) install --upgrade setuptools pip
 
install_requirements: update_tools $(REQUIREMENTS)
	$(PIP) install -r $(REQUIREMENTS)
 
install: install_requirements $(SETUP)
	$(PYTHON) $(SETUP) install
 
develop: install_requirements $(SETUP)
	$(PYTHON) $(SETUP) develop
 
test: $(SETUP) $(TEST_DIR)
	$(PYTHON) $(SETUP) test --pytest-args='--cov $(PACKAGE) $(TEST_DIR)'
            
;

public by huanshuai  2741  0  5  0

Flask Manager

#!/usr/bin/env python
import pprint
 
from flask import Flask, current_app
from flask_script import Manager, prompt_choices, Server
from main import app
 
manager = Manager(app)
 
if __name__ == "__main__":
    manager.run()
;

public by huanshuai  4532  8  4  1

flask index route

flask index route : routes.py
@web.route('/', methods=['GET'])
def index():
    return render_template('index.html')
;

public by huanshuai  219444  1  6  1

Get logging config and start logging in Python

import logging
import os.path

SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))

def main():
    log_path = os.path.join(SCRIPT_DIR, 'logging.conf')
    logging.config.fileConfig(log_path, disable_existing_loggers=False)
    logger.info("start logging!")
;