def __init__(self, db): self.log = helper.getLogger(__name__) self.conn = sqlite3.connect(db) self.opened = True self.log.debug('DB connected successfully.')
import ConfigParser import copy import json import os import urllib2 import helper __author__ = 'spance' log = helper.getLogger(__name__) __configuration__ = None def getConfiguration(): """ get current configuration copy. :return: may be None if never call the "init_and_validate" at before. """ return copy.deepcopy(__configuration__) if __configuration__ else None class AppConfig(object): def __init__(self): self.sys = None self.methods = [] @staticmethod def init_and_validate(): """ init gnoti.conf to configuration object, and validate it.
# @Version : $Id$ import datetime import getpass import json import time import re import pathlib import requests from fake_useragent import UserAgent from lxml import html import helper import image_helper logger = helper.getLogger('Baacloud') CURRENT_TIME = datetime.datetime.now() BASEDIR = pathlib.Path(__file__).parent CONFIG_FILE = BASEDIR / 'config/baacloud.json' HEADER = { 'content-type': 'application/x-www-form-urlencoded', 'origin': helper.getLatestServerUrl(), 'user-agent': UserAgent().chrome } def string(data): if isinstance(data, bytes): return data.decode()
# @Link : http://example.org # @Version : $Id$ import datetime import random import flask from flask import render_template, redirect from flask_admin import Admin from flask_admin.contrib.sqla import ModelView from flask_sqlalchemy import SQLAlchemy import helper import config logger = helper.getLogger('train') app = flask.Flask('train') app.config.from_pyfile('config.py') db = SQLAlchemy(app) class User(db.Model): userId = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(64), nullable=False, unique=True) username = db.Column(db.String(64)) gender = db.Column(db.Enum('male', 'female')) birthday = db.Column(db.DateTime()) phone = db.Column(db.String(64)) email = db.Column(db.String(64)) website = db.Column(db.String(64))
import ConfigParser import copy import json import os import urllib2 import helper __author__ = 'spance' log = helper.getLogger(__name__) __configuration__ = None def getConfiguration(): """ get current configuration copy. :return: may be None if never call the "init_and_validate" at before. """ return copy.deepcopy(__configuration__) if __configuration__ else None class AppConfig(object): def __init__(self): self.sys = None self.methods = [] @staticmethod
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2019-07-10 10:41:16 # @Author : Your Name ([email protected]) # @Link : http://example.org # @Version : $Id$ import config import helper import image_helper logger = helper.getLogger('percent', filePath='percent.log') def main(): successCount = 0 for inx, imageFile in enumerate( config.MARKED_CAPTCHA_FOLDER.rglob('*.png')): logger.info('Process %s', imageFile) originText = imageFile.parent.name captchaText = image_helper.recognizeImage(imageFile) logger.info('Captcha %s', captchaText) if captchaText == originText: successCount += 1 logger.info('Percent %s', (successCount / (inx + 1))) if __name__ == '__main__': main()
def onGetErrorLog(self, data): self.logs.append('siteId:{} {}'.format(self.siteId, str(data.log))) if len(self.logs) > 100: helper.getLogger(self.type, self.subType, self.siteId).error('\n'.join(self.logs)) self.logs = []