class Respondent(Resource):
    #method_decorators = [auth] # If you want apply to some method use: {'post': [auth],'put': [auth]}
    def __init__(self):
        self.log = Logger()
        self.db = DB().client

    def get(self, name=None):
        if (name):
            typeGet = "GET ONE"
            respondents = self.db.respondents.find_one({"firstName": name})
        else:
            typeGet = "GET ALL"
            respondents = self.db.respondents.find({})

        if (typeGet == "GET ALL"
                and respondents.count() > 0) or (typeGet == "GET ONE"
                                                 and respondents):
            return jsonify(code=200, type=typeGet, data=dumps(respondents))
        else:
            return None, 400

    def post(self):
        self.log.info('This a example info')
        self.log.debug('This a example debug')
        self.log.silly(request.form)
        self.log.warn('This is a example warn')
        self.log.error('This is a example error')
        return request.form
Ejemplo n.º 2
0
def crawl_thread(url, module):
    Logger.debug('Thread start')
    encoding = getattr(module, 'ENCODING', None)
    try:
        soup = get_b_soup(url, encoding=encoding)
        module.crawl(soup)
    except:
        Logger.error('Crawl error url: ' + url)
        Logger.error(traceback.format_exc())
        return
    Logger.debug('Thread done')
Ejemplo n.º 3
0
def crawl_thread(url, module):
    Logger.debug('Thread start')
    encoding = getattr(module, 'ENCODING', None)
    try:
        soup = get_b_soup(url, encoding=encoding)
        module.crawl(soup)
    except:
        Logger.error('Crawl error url: ' + url)
        Logger.error(traceback.format_exc())
        return
    Logger.debug('Thread done')
Ejemplo n.º 4
0
class Respondent(Resource):
    #method_decorators = [auth] # If you want apply to some method use: {'post': [auth],'put': [auth]}
    def __init__(self):
        self.log = Logger()
        self.db = DB().client

    def get(self, name=None):
        self.log.info('example info')
        self.log.debug('example debug')
        self.log.silly(name)
        self.log.warn('example warn')
        self.log.error('example error')
        match = {}
        if name:
            match = {"firstName": name}

        respondents = self.db.respondents.find(match)
        if respondents:
            return jsonify(code=200, data=dumps(respondents))
        else:
            return None, 400
Ejemplo n.º 5
0
            img_title = purifyName(tit[0])
            win32api.SetConsoleCtrlHandler(onClose, True)
            downnum, failnum = download(title=img_title,
                                        links=links[index][0],
                                        names=names[index][0],
                                        downnum=DOWN_NUM,
                                        failnum=FAIL_NUM,
                                        delta=delta,
                                        done=done)
            index += 1
            DOWN_NUM += downnum
            FAIL_NUM += failnum
    except (BaseException, Exception) as e:
        os.chdir(MAIN_PATH)
        lastTitle = MAIN_PATH + '\\Download\\' + purifyName(END_NAME)
        rmFile(lastTitle)
        with open('last.txt', 'w') as f:
            f.write(END_NAME)
        err_log = Logger(log_name='Error.log', logger_name='err').get_logger()
        err_log.error(e)
    finally:
        if os.getcwd() != MAIN_PATH:
            os.chdir(MAIN_PATH)
        output_log = Logger(log_name='Output.log',
                            logger_name='output').get_logger()
        output_log.info('下载完成%d张' % DOWN_NUM)
        output_log.info('下载失败%d张' % FAIL_NUM)
        print('>>>The log file in %s.<<<' % MAIN_PATH)
    print('Done!')
    input('\n\nPress any key to quit.')