Ejemplo n.º 1
0
    def getImages(self, request, queryset, *arg1, **arg2):
                for image in queryset:
                        logger.info('start to fetch images,The url is %s', image.oldurl)
                        try:
                                if image.stat == 1:
                                    pass
                                else:
                                    name = htmllib.sid() + '.jpg'
                                    result = getpage(htmllib.encoding(image.oldurl), 30)
                                    if result.code == 200:
                                            result = self.__store_images(result.read(), name, image)
                                    else:
                                            result = False
                                    if result:
                                            logger.info('Success!')
                                    else:
                                            logger.info('this one was Fail!')

                        except Exception, data:
                                logger.info(data)
Ejemplo n.º 2
0
    def __store_entry(self, feed):
                try:


                    entry, result = Entry.published.get_or_create(title=feed.title)
                    entry.excerpt = htmllib.Filter_html(feed.excerpt).strip()[:80] + u'……'
                    entry.status = 2
                    entry.author_name = htmllib.decoding(feed.author_name)
                    entry.date = feed.date
                    entry.slug = htmllib.sid() 
                    entry.content = htmllib.decoding(self.__Parse_image(feed.content))
                    entry.categories.add(feed.feed.category)
                    entry.sites = [Site.objects.get_current(), ]             
                    entry.save()
                    feed.fetch_stat = 4
                    feed.save()
                except Exception, data:
                        logger.error('the db saved error is: %s', data)
                        feed.fetch_stat = 3
                        feed.save()