Example #1
0
    def make_object(self, data):
        try:
            print data['url']
            u = urlopen(data['url'])
        except:
            raise URLOpenError("Can't access Url")

        parser = FeedParser()
        if not parser.parse(u):
            abort(400)
        feed = Feed(**parser.feed)
        feed.user_id = g.current_user.id
        for item in parser.items:
            new_item = Item(**item)
            new_item.feed_title = feed.title
            feed.items.append(new_item)
        g.current_user.feeds.append(feed)
        db.session.add(g.current_user)
        db.session.commit()
        return feed