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


Python Book.cover_image方法代码示例

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


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

示例1: handle

# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import cover_image [as 别名]
	def handle(self, *args, **options):
		series, created = Series.objects.get_or_create(name='freiesMagazin')
		binding, created = Binding.objects.get_or_create(name='E-Book')
		language, created = Language.objects.get_or_create(name='Deutsch')
		volume = Book.objects.filter(series=series).aggregate(Max('volume'))['volume__max']
		if volume == None:
			volume = 0
			month = (2006, 2)
		else:
			title = Book.objects.get(series=series, volume=volume).title
			month = (int(title[-4:]), int(title[-7:-5]))

		code = HTTP.OK
		while code == HTTP.OK:
			volume += 1
			month = next(month)
			try:
				code = urlopen('http://www.freiesmagazin.de/freiesMagazin-%d-%02d' % (month[0], month[1])).code
				if code == HTTP.OK:
					self.stdout.write('Adding Issue %d (%02d/%d)...' % (volume, month[1], month[0]))
					book = Book(title='freiesMagazin %02d/%d' % (month[1], month[0]), series=series, volume=volume, binding=binding, published_on=date(year=month[0], month=month[1], day=1), purchased_on=date.today())
					book.save()
					book.languages.add(language)
					book.save()

					folder = join(settings.MEDIA_ROOT, 'books', str(book.id))
					if not exists(folder):
						makedirs(folder)

					image = join(folder, 'cover.jpg')
					try:
						urlretrieve('http://www.freiesmagazin.de/system/files/freiesmagazin-%d-%02d.png' % (month[0], month[1]), image)
						book.cover_image = image
						book.save()
					except HTTPError as e:
						pass

					name = slugify('freiesMagazin-%d-%02d' % (month[0], month[1])) + '.pdf'
					pdf = join(folder, name)
					urlretrieve('http://www.freiesmagazin.de/ftp/%d/freiesMagazin-%d-%02d.pdf' % (month[0], month[0], month[1]), pdf)
					EBookFile.objects.create(ebook_file=join('books', str(book.id), name), book=book)

					try:
						name = slugify('freiesMagazin-%d-%02d' % (month[0], month[1])) + '.epub'
						epub = join(folder, name)
						urlretrieve('http://www.freiesmagazin.de/ftp/%d/freiesMagazin-%d-%02d-bilder.epub' % (month[0], month[0], month[1]), epub)
						EBookFile.objects.create(ebook_file=join('books', str(book.id), name), book=book)
					except HTTPError as e:
						pass

					Url.objects.create(url='http://www.freiesmagazin.de/freiesMagazin-%d-%02d' % (month[0], month[1]), book=book)
					book.save()
			except HTTPError as e:
				self.stdout.write('No Issue %d (%02d/%d), stopping.' % (volume, month[1], month[0]))
				break
开发者ID:jnphilipp,项目名称:buecher,代码行数:57,代码来源:freiesMagazin.py

示例2: handle

# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import cover_image [as 别名]
	def handle(self, *args, **options):
		series, created = Series.objects.get_or_create(name='Full Circle Magazine')
		binding, created = Binding.objects.get_or_create(name='E-Book')
		language, created = Language.objects.get_or_create(name='Englisch')
		volume = Book.objects.filter(series=series).aggregate(Max('volume'))['volume__max']
		if volume == None:
			volume = 0

		code = HTTP.OK
		while code == HTTP.OK:
			volume += 1
			try:
				code = urlopen('http://fullcirclemagazine.org/issue-%d/' % volume).code
				if code == HTTP.OK:
					self.stdout.write('Adding Issue %d...' % volume)
					book = Book(title='Issue %d' % volume, series=series, volume=volume, binding=binding, purchased_on=date.today())
					book.save()
					book.languages.add(language)
					book.save()

					folder = join(settings.MEDIA_ROOT, 'books', str(book.id))
					if not exists(folder):
						makedirs(folder)

					image = join(folder, 'cover.jpg')
					urlretrieve('http://dl.fullcirclemagazine.org/cover/%d/xen.jpg.pagespeed.ic.OYt0Nw3Yh8.jpg' % volume, image)
					book.cover_image = image
					book.save()

					name = slugify('Issue %d' % volume) + '.pdf'
					pdf = join(folder, name)
					urlretrieve('http://dl.fullcirclemagazine.org/issue%d_en.pdf' % volume, pdf)
					EBookFile.objects.create(ebook_file=join('books', str(book.id), name), book=book)

					name = slugify('Issue %d' % volume) + '.epub'
					epub = join(folder, name)
					urlretrieve('http://dl.fullcirclemagazine.org/issue%d_en.epub' % volume, epub)
					EBookFile.objects.create(ebook_file=join('books', str(book.id), name), book=book)

					Url.objects.create(url='http://fullcirclemagazine.org/issue-%d/' % volume, book=book)
					book.save()
			except HTTPError as e:
				self.stdout.write('No Issue %d, stopping.' % volume)
				break
开发者ID:jnphilipp,项目名称:buecher,代码行数:46,代码来源:fullcircle.py


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