def extract_comments(self, sid, text): """ Extracts comments from a XML string. The parsing is done using feedparser library. :param sid: the id of the new. :param text: the RSS xml. """ parsed = feedparser.parse(text) try: published = parsed.feed.published except AttributeError: published = parsed.feed.updated comments = [] for comment in parsed.entries: meneame_comment = Comment(sid) meneame_comment.order = comment['meneame_order'] meneame_comment.karma = comment['meneame_karma'] meneame_comment.user = comment['meneame_user'] meneame_comment.votes = comment['meneame_votes'] meneame_comment.id = comment['meneame_comment_id'] try: meneame_comment.published = comment.published except AttributeError: meneame_comment.published = comment.updated meneame_comment.summary = comment.summary comments.append(meneame_comment) return comments, published
def response(): if config.memcache.db: clearmem() action = cgi_get("action", choices=["post", "videopost", "comment", "photo", "photoset", "md"]) if action == "md": for dn, dz, fz in os.walk("md"): succeed([f[:-3] for f in fz]) user = cgi_get("user") if action == "comment": ent = Comment(user=user, post=cgi_get("post"), body=cgi_get("body")) elif action == "photo": pkey = cgi_get("key", required=False) if pkey: ent = Photo.query(Photo.key == pkey).get() else: ent = Photo() capt = cgi_get("caption", required=False) # imgs uploaded separately if capt: ent.caption = capt else: blurb = cgi_get("blurb", required=False) pkey = cgi_get("key", required=False) tags = cgi_get("tags", required=False) pmod = db.get_model(action) if pkey: ent = pmod.query(pmod.key == pkey).get() else: ent = pmod(user=user) ent.title = cgi_get("title") ent.live = cgi_get("live") if blurb: ent.blurb = blurb if tags: ent.tags = tags if action == "post": ent.body = cgi_get("body") ent.put() if action == "photo": # get photoset psk = cgi_get("photoset", required=False) if psk: ps = db.get(psk) # these are hacky -- fix list ops in ct if cgi_get("remove", default=False): # ps.photos.remove(ent.key) ps.photos = [p for p in ps.photos if p != ent.key] else: # ps.photos.append(ent.key) ps.photos = ps.photos + [ent.key] ps.put() succeed(ent.id())