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


Python DB.db方法代码示例

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


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

示例1: run

# 需要导入模块: import DB [as 别名]
# 或者: from DB import db [as 别名]
    def run(self):
        """
        Do the actual downloading of documents
        """
        # Grab the URLs to download
        db = DB.db()

	i = 0

        # Loop through them and actually download and save
        while 1:
            urls = db.multirow("select url from rdfs_grab_urls(%d, %s, '90 days'::reltime)" % (self.n_docs, db.dbstr(self.getName())))
            self.log("urls to dl (run %s): %s" % (i,len(urls)))

	    i += 1

            if len(urls) == 0:
                break

            for url_row in urls:
                url= url_row["url"]
                self.log("grabbing %s" % url)
                try:
                    doc = document.Document(url)
                    doc.grab()
                except:
                    self.log("couldn't download URL %s" % url)
                    self.touchURL(db, url, 'comatose')
                    continue
                self.log("done grabbing %s" % url)

                # If we get here, then the URL has been successfully downloaded and,
                # even if we fail later, we don't want to have to deal with reloading it again
                self.touchURL(db, url)

                try:
                    doc.parse()
                except RuntimeError, (strerror):
                    self.log("couldn't parse URL %s: %s" % (url,strerror))
                    continue
                except:
                    self.log("couldn't parse URL %s" % url)
开发者ID:cc-archive,项目名称:__cvs_import,代码行数:44,代码来源:documentdownloader.py

示例2: slash

# 需要导入模块: import DB [as 别名]
# 或者: from DB import db [as 别名]
        url = self.url
	db_url = db.dbstr(url)

        # Fix the license_url if it has no end slash (old licenses!)
        # TODO: change this to query the license from CC and use the built-in 302 redirect to do the right thing
        license_url = work.licenses()[0]
        if license_url[-1] != "/":
            license_url += "/"
	db_license_url = db.dbstr(license_url)

        # First make sure the URL is in there (in case it's changed)
        db.perform("select rdfs_url_new(%s, %d)" % (db_url, Document.method_id))

        query = "select rdfs_store_document(%s, rdfs_get_license_id(%s), %s, %s, %s, %s, %s, %s)" % (db_url, db_license_url, db_title, db_date, db_description, db_creator, db_type, db_raw_text)

        # do the update in the DB
        db.perform(query.encode('utf-8','ignore'))


# Test
if __name__ == "__main__":
    #doc= Document('http://shyflower.com/art/Themes/AllAmerican/amer.htm')
    #doc= Document('http://commoncontent.org/catalog/images/clipart/505/xml')
    #doc = Document('http://thecrankyone.diaryland.com/lotsanothin.html')
    #doc = Document('http://thejugglers.org/archives/2003_05.php')
    #doc = Document('http://gondwanaland.com/ml/')
    doc = Document(sys.argv[1])
    doc.grab()
    doc.parse()
    doc.store(DB.db())
开发者ID:cc-archive,项目名称:__cvs_import,代码行数:32,代码来源:document.py


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