Last active
October 13, 2020 07:03
-
-
Save ourdaidai/f745fa953ab085603863bc98e262c3ed to your computer and use it in GitHub Desktop.
[config_logging_mysql] #python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| """ | |
| Created on Fri Aug 28 10:06:04 2020 | |
| @author: tangliang | |
| """ | |
| import pymysql | |
| import pandas as pd | |
| from tqdm import tqdm | |
| import time | |
| import datetime | |
| import os | |
| import json | |
| import logging | |
| import re | |
| LOG_FORMAT = "%(asctime)s %(name)s %(levelname)s %(pathname)s %(message)s " # 配置输出日志格式 | |
| DATE_FORMAT = '%Y-%m-%d %H:%M:%S %a ' # 配置输出时间的格式,注意月份和天数不要搞乱了 | |
| logging.basicConfig(level=logging.DEBUG, | |
| format=LOG_FORMAT, | |
| datefmt=DATE_FORMAT, | |
| ) | |
| try: | |
| res = self.__parse_json(res['result']['data']) | |
| except Exception as e: | |
| logging.error('__parse_json 出错: {}'.format(e)) | |
| logging.error(res) | |
| config_path = os.path.dirname(os.path.abspath(__file__))+'/config.json' | |
| # config_file = json.load(open(config_path, 'r', encoding='utf-8')) | |
| config_file = { | |
| "graph_host": "", | |
| "graph_port": "8182", | |
| "mysql_host": "", | |
| "mysql_user": "", | |
| "mysql_password": "" | |
| } | |
| configs = {"mysql_port":3306} | |
| configs.update(config_file) | |
| def mysql_connect(database: str): | |
| IP = configs["mysql_host"] | |
| # IP = '127.0.0.1' | |
| # user = '' | |
| # password = '' | |
| user = configs["mysql_user"] | |
| password = configs["mysql_password"] | |
| database = database | |
| port = int(configs["mysql_port"]) | |
| conn = pymysql.connect(host=IP, user=user, password=password, db=database, port=port) | |
| return conn | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment