当前位置: 首页>>代码示例>>Python>>正文


Python DB.createTableIfNotExist方法代码示例

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


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

示例1: main

# 需要导入模块: from lib.db import DB [as 别名]
# 或者: from lib.db.DB import createTableIfNotExist [as 别名]
def main():

    scrapperFactory = ScrapperFactory()

    cfg = Config("conf/scrapper.conf")

    if (cfg.readConfig() == False):
        print( "[Main - readConfig] [Error reading config file]" )
        return

    if (cfg.createLog() == False):
        print( "[Main - createLog] [Error creating log files]" )
        return

    cfg.log.info( "[ Main - readConfig ] [ Config file read sucessfully ]" )
    cfg.log.info( "[ Main - createLog ] [ Log files created successfully ]" )
    cfg.log.info( "[ Scrapper ] - [ This is Major Tom to Ground Control! ]" )

    cfg.log.info( "[ Scrapper ] - [ Here are my orders ]" )

    for website in cfg.websitesConf:
        cfg.log.info( "[ Scrapper ] - [ Website -> \"{}\" ]".format( website ) )
        for section in cfg.websitesConf[website]:
            cfg.log.info( "[ Scrapper ] - [ \tSection -> \"{}\" ]".format( section ) )
            cfg.log.info( "[ Scrapper ] - [ \t\turl -> \"{}\" ]".format( cfg.websitesConf[website][section]["url"] ) )
            cfg.log.info( "[ Scrapper ] - [ \t\tslug -> \"{}\" ]".format( cfg.websitesConf[website][section]["slug"] ) )


    db = DB(cfg)
    wpinfo = { "website" : cfg.wphost, "user" : cfg.wpuser, "pass" : cfg.wppass }

    if db.hasError():
        cfg.log.info( "[ Scrapper ] - [ Conection to database has failed ]".format( website ) )
        cfg.log.error( "[ Scrapper ] - [ Conection to database has failed ]".format( website ) )
        return

    for website in cfg.websitesConf:
        cfg.log.info( "[ Scrapper ] - [ Looking for \"{}\" sections ]".format( website ) )
        for section in cfg.websitesConf[website]:
            # table name and type are the same as section name
            cfg.log.info( "[ Scrapper ] - [ Accesing to \"{}\" table ]".format( section ) )
            db.createTableIfNotExist( section )
            cfg.log.info( "[ Scrapper ] - [ Calling \"{}\" scrapper ]".format( section ) )

            #factory -> ( type, db, wpinfo, table, url, slug, log )
            scrapperInstance = scrapperFactory.factory( section, db, wpinfo, section, cfg.websitesConf[website][section]["url"], cfg.websitesConf[website][section]["slug"], cfg.log )

            cfg.log.info( "[ Scrapper ] - [ \"{}\" scrapper begins ]".format( section ) )
            scrapperInstance.scrape()
            cfg.log.info( "[ Scrapper ] - [ \"{}\" scrapper has finished ]".format( section ) )

            scrappedItems = scrapperInstance.numberOfItems()

            cfg.log.info( "[ Scrapper ] - [ \"{}\" scrapper has scrapped {} new items ]".format( section, scrappedItems ) )

            if scrappedItems:
                cfg.log.info( "[ Scrapper \"{}\" ] - [ storing items into db ]".format( section ) )
                scrapperInstance.addItemsToMysql()
                cfg.log.info( "[ Scrapper \"{}\" ] - [ writting articles into Wordpress ]".format( section ) )
                scrapperInstance.addItemsToWordpress()


                cfg.log.info( "[ Scrapper ] - [ Bye ]" )
                scrapperInstance.addItemsToWordpress()
开发者ID:a-castellano,项目名称:NewsScrapper,代码行数:66,代码来源:scrapperManager.py


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