# Path: web/util/db.py
# def get_db(database=None):


import datetime
import time
import feedparser
        import tldextract
from web.util.db import db
        from .user_feed import Sub
        pass

    @classmethod
    def get_feed_items_by_site(cls,site,limit=15,offset=0):
        start       = offset*limit
        end         = offset*limit + limit
        return cls.objects(feedsite=site)[start:end]

    @classmethod
    def is_saved(cls, title=None, date=None):
        return cls.objects(title=title, create_date=date).first() is not None

    def to_dict(self, user=None):
        d = {
                "id":str(self.id),
                "title":self.title,
                "link":self.link,
                "content":self.content,
                "summary":self.summary,
                "createDate":self.create_date.strftime("%Y-%m-%d %H:%M"),
                "feedsiteid":str(self.feedsite.id),
                "author":self.feedsite.title
        }

        if user is not None:
            d["isStared"] = user.has_stared_feed(feed=self)
            d["isRead"] = user.has_read(feed=self)
        return d



# Path: web/util/db.py
# def get_db(database=None):


# Path: web/model/feed.py
import datetime
import time
import feedparser
        import tldextract
from web.util.db import db
        from .user_feed import Sub

        pass

    @classmethod
    def get_feed_items_by_site(cls,site,limit=15,offset=0):
        start       = offset*limit
        end         = offset*limit + limit
        return cls.objects(feedsite=site)[start:end]

    @classmethod
    def is_saved(cls, title=None, date=None):
        return cls.objects(title=title, create_date=date).first() is not None

    def to_dict(self, user=None):
        d = {
                "id":str(self.id),
                "title":self.title,
                "link":self.link,
                "content":self.content,
                "summary":self.summary,
                "createDate":self.create_date.strftime("%Y-%m-%d %H:%M"),
                "feedsiteid":str(self.feedsite.id),
                "author":self.feedsite.title
        }

        if user is not None:
            d["isStared"] = user.has_stared_feed(feed=self)
            d["isRead"] = user.has_read(feed=self)
        return d



class FeedSite(db.Document):