本文整理汇总了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()