• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python db.DB类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中src.tools.db.DB的典型用法代码示例。如果您正苦于以下问题:Python DB类的具体用法?Python DB怎么用?Python DB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了DB类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __get_question_list

    def __get_question_list(self):
        question_list = [DB.wrap('question', x) for x in DB.get_result_list(self.sql.question)]
        answer_list = [DB.wrap('answer', x) for x in DB.get_result_list(self.sql.get_answer_sql())]

        def merge_answer_into_question():
            question_dict = {x['question_id']: {'question': x.copy(), 'answer_list': [], 'agree': 0} for x in
                             question_list}
            for answer in answer_list:
                question_dict[answer['question_id']]['answer_list'].append(answer)
            return question_dict.values()

        def add_property(question):
            agree_count = 0
            char_count = 0
            for answer in question['answer_list']:
                answer['char_count'] = len(answer['content'])
                answer['agree_count'] = answer['agree']
                answer['update_date'] = answer['edit_date']
                agree_count += answer['agree']
                char_count += answer['char_count']
            question['answer_count'] = len(question['answer_list'])
            question['agree_count'] = agree_count
            question['char_count'] = char_count
            return question

        question_list = [add_property(x) for x in merge_answer_into_question() if len(x['answer_list'])]
        return question_list
开发者ID:daoli,项目名称:ZhihuHelp__Python,代码行数:27,代码来源:initialbook.py


示例2: login

    def login(self, account, password, captcha=''):
        content = Http.get_content('https://www.zhihu.com/')
        xsrf = Match.xsrf(content)
        if not xsrf:
            Debug.logger.info(u'登陆失败')
            Debug.logger.info(u'敲击回车重新发送登陆请求')
            return False
        xsrf = xsrf.split('=')[1]
        # add xsrf as cookie into cookieJar,
        cookie = Http.make_cookie(name='_xsrf', value=xsrf, domain='www.zhihu.com')
        self.cookieJar.set_cookie(cookie)
        if captcha:
            post_data = {'_xsrf': xsrf, 'email': account, 'password': password, 'remember_me': True,
                         'captcha': captcha}
        else:
            post_data = {'_xsrf': xsrf, 'email': account, 'password': password, 'remember_me': True}

        header = {
            'Accept': '*/*',
            'Accept-Encoding': 'gzip,deflate',  # 主要属性,只要有此项知乎即认为来源非脚本
            'Accept-Language': 'zh,zh-CN;q=0.8,en-GB;q=0.6,en;q=0.4',
            'Host': 'www.zhihu.com',
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
            'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36(KHTML, like Gecko)Chrome/34.0.1847.116 Safari/537.36',
            'Connection': 'keep-alive',
            'X-Requested-With': 'XMLHttpRequest',
            'Origin': 'https://www.zhihu.com',
            'Referer': 'https://www.zhihu.com/',
        }
        result = Http.get_content(url=r'https://www.zhihu.com/login/email', data=post_data, extra_header=header)
        if not result:
            Debug.logger.info(u'登陆失败,请敲击回车重新登陆')
            return False
        response = json.loads(result)

        if response['r'] == 0:
            print u'登陆成功!'
            print u'登陆账号:', account
            print u'请问是否需要记住帐号密码?输入yes记住,输入其它任意字符跳过,回车确认'
            if raw_input() == 'yes':
                Config.account, Config.password, Config.remember_account = account, password, True
                print u'帐号密码已保存,可通过修改config.json修改设置'
            else:
                Config.account, Config.password, Config.remember_account = '', '', False
                print u'跳过保存环节,进入下一流程'
            Config._save()
            cookie = self.get_cookie()
            data = {}
            data['account'] = account
            data['password'] = password
            data['recordDate'] = ExtraTools.get_today()
            data['cookieStr'] = cookie
            DB.save(data, 'LoginRecord')
            DB.commit()
            return True
        else:
            print u'登陆失败'
            Debug.print_dict(response)
            return False
开发者ID:LichAmnesia,项目名称:ZhihuHelp,代码行数:59,代码来源:login.py


示例3: save

 def save(self):
     self.clear_index()
     save_config = self.create_save_config()
     for key in save_config:
         for item in save_config[key]:
             if item:
                 DB.save(item, key)
     DB.commit()
     return
开发者ID:FengWenPei,项目名称:ZhihuHelp,代码行数:9,代码来源:worker.py


示例4: query_answer_list_by_author_page_id

 def query_answer_list_by_author_page_id(self, author_page_id):
     # 需要先查出来对应的author_id
     author_info = DB.query_row(u'select author_id from Author where author_page_id="{author_page_id}"'.format(author_page_id=author_page_id))
     author_id = author_info[u'author_id']
     raw_answer_list = DB.query_all(u'select * from Answer where author_id="{author_id}"  {order_by} '.format(author_id=author_id, order_by=Config.answer_order_by))
     answer_list = []
     for raw_answer in raw_answer_list:
         answer_list.append(self.format_answer(raw_answer))
     return answer_list
开发者ID:EleVenPerfect,项目名称:OTHERS,代码行数:9,代码来源:task_result.py


示例5: __init__

 def __init__(self):
     #   初始化目录结构
     Path.init_base_path()
     Path.init_work_directory()
     #   初始化数据库链接
     DB.init_database()
     #   初始化配置
     Config.init_config()
     return
开发者ID:EleVenPerfect,项目名称:OTHERS,代码行数:9,代码来源:main.py


示例6: save_record_list

 def save_record_list(table_name, record_list):
     """
     将数据保存到数据库中
     :return:
     """
     for record in record_list:
         DB.save(record, table_name)
     DB.commit()
     return
开发者ID:EleVenPerfect,项目名称:OTHERS,代码行数:9,代码来源:worker.py


示例7: __get_article_list

    def __get_article_list(self):
        def add_property(article):
            article['char_count'] = len(article['content'])
            article['agree_count'] = article['agree']
            article['update_date'] = article['publish_date']
            article['answer_count'] = 1
            return article

        article_list = [DB.wrap(Type.article, x) for x in DB.get_result_list(self.sql.get_answer_sql())]
        article_list = [add_property(x) for x in article_list]
        return article_list
开发者ID:daoli,项目名称:ZhihuHelp__Python,代码行数:11,代码来源:initialbook.py


示例8: __get_article_list

    def __get_article_list(self):
        def add_property(article):
            article['char_count'] = len(article['content'])
            article['answer_count'] = 1
            # TODO
            if self.kind in [Type.jianshu_author, Type.jianshu_collection, Type.jianshu_notebooks,
                             Type.sinablog_author, Type.csdnblog_author]:
                article['agree_count'] = "没有赞同数"     # article['agree']
            else:
                article['agree_count'] = article['agree']

            article['update_date'] = article['publish_date']

            return article

        if self.kind in [Type.jianshu_author, Type.jianshu_collection, Type.jianshu_notebooks]:
            article_list = [DB.wrap(Type.jianshu_article, x) for x in DB.get_result_list(self.sql.get_answer_sql())]
        elif self.kind == Type.sinablog_author:
            article_list = [DB.wrap(Type.sinablog_article, x) for x in DB.get_result_list(self.sql.get_answer_sql())]
        elif self.kind == Type.csdnblog_author:
            article_list = [DB.wrap(Type.csdnblog_article, x) for x in DB.get_result_list(self.sql.get_answer_sql())]
        else:
            article_list = [DB.wrap(Type.article, x) for x in DB.get_result_list(self.sql.get_answer_sql())]
        article_list = [add_property(x) for x in article_list]
        return article_list
开发者ID:gitter-badger,项目名称:EE-Book,代码行数:25,代码来源:initialbook.py


示例9: catch_info

 def catch_info(self):
     info = {}
     if self.property.sql.info:
         info = DB.cursor.execute(self.property.sql.info).fetchone()
         info = DB.wrap(Type.info_table[self.kind], info)
     self.set_info(info)
     return
开发者ID:hmilyfyj,项目名称:ZhihuHelp__Python,代码行数:7,代码来源:book.py


示例10: query_question_list

 def query_question_list(self, question_id_list):
     raw_question_list = DB.query_all(
         u'select * from Question where question_id in ({question_id_list})'.format(question_id_list=','.join(question_id_list)))
     question_list = []
     for raw_question in raw_question_list:
         question_list.append(self.format_question(raw_question))
     return question_list
开发者ID:EleVenPerfect,项目名称:OTHERS,代码行数:7,代码来源:task_result.py


示例11: query_question

 def query_question(self, question_id):
     """
     :rtype: Question_Info
     """
     question = DB.query_row(u'select * from Question where question_id in ({question_id})'.format(question_id=question_id))
     question = self.format_question(question)  # 包装成标准的信息格式
     return question
开发者ID:EleVenPerfect,项目名称:OTHERS,代码行数:7,代码来源:task_result.py


示例12: catch_article_book_info

 def catch_article_book_info(self, sql):
     info_list = DB.cursor.execute(self.sql.info).fetchall()
     info_list = [DB.wrap(Type.article, item) for item in info_list]
     info = {}
     info['title'] = '_'.join([str(item['title']) for item in info_list])
     info['id'] = '_'.join([str(item['article_id']) for item in info_list])
     return info
开发者ID:daoli,项目名称:ZhihuHelp__Python,代码行数:7,代码来源:initialbook.py


示例13: catch_question_book_info

 def catch_question_book_info(self, sql):
     info_list = DB.cursor.execute(self.sql.info).fetchall()
     info_list = [DB.wrap(Type.question, item) for item in info_list]
     info = dict()
     info['title'] = '_'.join([str(item['title']) for item in info_list])   # 可以是多个问题, 多个id联系在一起
     info['id'] = '_'.join([str(item['question_id']) for item in info_list])
     return info
开发者ID:gitter-badger,项目名称:EE-Book,代码行数:7,代码来源:initialbook.py


示例14: query_answer_list_by_question_id

 def query_answer_list_by_question_id(self, question_id):
     raw_answer_list = DB.query_all(
         u'select * from Answer where question_id="{question_id}" {order_by} '.format(question_id=question_id, order_by=Config.answer_order_by))
     answer_list = []
     for raw_answer in raw_answer_list:
         answer_list.append(self.format_answer(raw_answer))
     return answer_list
开发者ID:EleVenPerfect,项目名称:OTHERS,代码行数:7,代码来源:task_result.py


示例15: query_article_list_by_column_id

 def query_article_list_by_column_id(self, column_id):
     #   根据发表时间正序获取文章列表,方便浏览
     raw_article_list = DB.query_all(u'select * from Article where column_id="{column_id}"  {order_by}'.format(column_id=column_id, order_by=Config.article_order_by))
     article_list = []
     for raw_article in raw_article_list:
         article = self.format_article(raw_article)
         article_list.append(article)
     return article_list
开发者ID:EleVenPerfect,项目名称:OTHERS,代码行数:8,代码来源:task_result.py


示例16: query_answer

    def query_answer(self, answer_id):
        """

        :type answer_id:int
        :return:
        """
        answer = DB.query_row(u'select * from Answer where answer_id in ({answer_id})'.format(answer_id=answer_id))
        answer = self.format_answer(answer)
        return answer
开发者ID:EleVenPerfect,项目名称:OTHERS,代码行数:9,代码来源:task_result.py


示例17: catch_csdnblog_book_info

    def catch_csdnblog_book_info(self):
        u"""

        :return:
        """
        info_list = DB.cursor.execute(self.sql.info).fetchall()
        info_list = [DB.wrap(Type.csdnblog_info, item) for item in info_list]
        info = dict()
        info['creator_name'] = '_'.join([str(item['creator_name']) for item in info_list])
        info['creator_id'] = '_'.join([str(item['creator_id']) for item in info_list])
        return info
开发者ID:gitter-badger,项目名称:EE-Book,代码行数:11,代码来源:initialbook.py


示例18: catch_sinablog_book_info

    def catch_sinablog_book_info(self):
        u"""

        :param
        :return: info
        """
        info_list = DB.cursor.execute(self.sql.info).fetchall()
        info_list = [DB.wrap(Type.sinablog_info, item) for item in info_list]
        info = dict()
        info['creator_name'] = '_'.join([str(item['creator_name']) for item in info_list])  # 可以是多个博客组合在一起
        info['creator_id'] = '_'.join([str(item['creator_id']) for item in info_list])
        return info
开发者ID:gitter-badger,项目名称:EE-Book,代码行数:12,代码来源:initialbook.py


示例19: catch_info

 def catch_info(self):
     info = {}
     if self.sql.info:
         if self.kind in [Type.question, Type.answer]:
             info = self.catch_question_book_info(self.sql.info)
         elif self.kind == Type.article:
             info = self.catch_article_book_info(self.sql.info)
         else:
             info = DB.cursor.execute(self.sql.info).fetchone()
             info = DB.wrap(Type.info_table[self.kind], info)
     self.set_info(info)
     return
开发者ID:daoli,项目名称:ZhihuHelp__Python,代码行数:12,代码来源:initialbook.py


示例20: catch_jianshu_book_info

    def catch_jianshu_book_info(self):
        u"""

        :return: info
        """
        info_list = DB.cursor.execute(self.sql.info).fetchall()
        info_list = [DB.wrap(Type.jianshu_info, item) for item in info_list]
        info = dict()
        # 可以是多个博客组合在一起 TODO: 删掉???
        info['creator_name'] = '_'.join([str(item['creator_name']) for item in info_list])
        info['creator_id'] = '_'.join([str(item['creator_id']) for item in info_list])
        return info
开发者ID:gitter-badger,项目名称:EE-Book,代码行数:12,代码来源:initialbook.py



注:本文中的src.tools.db.DB类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python http.Http类代码示例发布时间:2022-05-27
下一篇:
Python RuleTestTemplate.RuleTest类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap