Example #1
0
def index(request):
    import datetime
    feed_list = feeds.get_list(feed_type__exact='planet', order_by=['title'])
    post_list = posts.get_list(feed__feed_type__exact='planet', order_by=['-modified'], limit=40)
    post_short_list = posts.get_list(feed__feed_type__exact='planet', modified__gt = (datetime.datetime.now() - datetime.timedelta(hours=24)), order_by=['-modified'], offset=41, limit=100)
    delicious_list = posts.get_list(feed__feed_type__exact='delicious', order_by=['-modified'], limit=20)
    return render_to_response('planetex/index', {'feeds':feed_list, 'posts':post_list, 'posts_short':post_short_list, 'delicious':delicious_list})
Example #2
0
def atom(request):
    feed_list = feeds.get_list(feed_type__exact='planet', order_by=['title'])
    post_list = posts.get_list(order_by=['-modified'], limit=40)
    content = loader.render_to_string('planetex/atom', {'feeds':feed_list, 'posts':post_list})
    return HttpResponse(content, mimetype='text/xml')
Example #3
0
 def update(self, feed=None, planet='planet'):
     """ Read new feed posts and publish them """
     if (_debug): print "Retrieving feed list..."
     if (feed <> None):
         feed_list = [feed]
     else:
         feed_list = feeds.get_list(feed_type__exact=planet)
     for feed in feed_list:
         if (_debug): print "Downloading %s..." % (feed.link_xml)
         # Download and parse the feeds
         try:
             params = dict()
             if (_debug): print "Etag: %s" % (feed.etag)
             ## if (feed.has_key('modified_parsed'): params['modified'] = feed.modified
             if (feed.etag <> ''):
                 p = feedparser.parse(feed.link_xml, etag=feed.etag)
             else:
                 p = feedparser.parse(feed.link_xml)
         except:
             if (_debug): print "Error downloading feed %s" % (feed.link_xml) 
             continue
         # Parse feed entries
         num = 0
         if (_debug): print "Saving new posts..."
         for post in p.entries:
             hash = self.__post_hash(post)
             # Check if post is already in database
             if (_debug): print "Checking if post exists... %s" % (hash)
             if (post.has_key('guid')):
                 if (_debug): print "guid... %s" % (post.guid)
                 old_post = posts.get_list(guid__exact = post.guid)
             else:
                 old_post = posts.get_list(hash__exact = hash)
             if (len(old_post) > 0):
                 # Post exists in database
                 if (_debug): print "Checking if post was updated... %s" % (old_post[0].hash)
                 if (old_post[0].hash <> hash):
                     # Publish post
                     if (_debug): print "Updating post..."
                     self.post_save(post, old_post[0])
                     if (_debug): print "Post updated."
                 else:
                     if (_debug): print "Post already published."
             else:
                 # Publish post
                 if (_debug): print "Publishing new post..."
                 self.post_save(post, feed = feed)
                 if (_debug): print "New post published."
         # Update feed data
         if (_debug): print "Updating feed data..."
         param = dict()
         if (p.has_key('etag')):
             param['etag'] = p.etag
         if (p.has_key('status')):
             param['status'] = p.status
         if (p.has_key('modified_parsed')):
             param['modified'] = datetime.datetime(*p.modified_parsed[:7])
         param['lastVisit'] = datetime.datetime.now()
         try:
             for field in param:
                 feed.__setattr__(field, param[field])
             if (_debug): print "Feed data updated."
         except:
             if (_debug): print "Error updating data."