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


Python Post.download方法代码示例

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


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

示例1: import_gbfavs

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import download [as 别名]
def import_gbfavs(password, userID):
	import xml.etree.ElementTree as ET
	
	favIDs = []
	offset = 0
	while True:
		data = urllib2.urlopen('http://gelbooru.com/index.php?page=favorites&s=view&id=%s&pid=%s' % (userID, offset)).read()
		
		matches = re.findall(r'href=\"index\.php\?page=post&s=view&id=(\d+)\"', data)
		if len(matches) == 0:
			break
		favIDs += matches
		offset = offset + len(matches)
	print "Found %s Favorites!" % len(favIDs)
	
	ctx = app.test_request_context()
	ctx.push()
	
	g.db = db_connect(password)
	
	for favID in reversed(favIDs):
		print "Downloading http://gelbooru.com/index.php?page=post&s=view&id=%s" % favID
		data = urllib2.urlopen('http://gelbooru.com/index.php?page=dapi&s=post&q=index&id=%s' % favID).read()
		root = ET.fromstring(data)
		if len(root) < 1:
			print "--> Not Found!"
		
		d = root[0].attrib
		
		post = Post.download(
			url=d['file_url'],
			tagnames=d['tags'].strip().split(' '),
			rating=d['rating']
		)
	ctx.pop()
开发者ID:uppfinnarn,项目名称:SecretBooru,代码行数:37,代码来源:cmd.py

示例2: import_url

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import download [as 别名]
def import_url():
	if request.method == 'POST':
		post = Post.download(
			url = request.form['url'],
			tagnames = request.form['tags'].strip().split(' '),
			rating = request.form['rating']
		)
		
		g.db.commit()
		
		return redirect(url_for('post', id=post.id))
	return render_template('import_url.html')
开发者ID:uppfinnarn,项目名称:SecretBooru,代码行数:14,代码来源:secretbooru.py

示例3: import_gelbooru

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import download [as 别名]
def import_gelbooru():
	if request.method == 'POST':
		import xml.etree.ElementTree as ET
		data = urllib2.urlopen('http://gelbooru.com/index.php?page=dapi&s=post&q=index&id=%s' % request.form['pid']).read()
		root = ET.fromstring(data)
		if len(root) < 1:
			abort(404)
		d = root[0].attrib
		
		post = Post.download(
			url=d['file_url'],
			tagnames=d['tags'].strip().split(' '),
			rating=d['rating']
		)
		
		return redirect(url_for('post', id=post.id))
	return render_template('import_gelbooru.html')
开发者ID:uppfinnarn,项目名称:SecretBooru,代码行数:19,代码来源:secretbooru.py


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