Ejemplo n.º 1
0
def get_feedurls(user=None, distinct=False):
    """
    Return a user's distinct feeds. If no user is specified,
    returns all distinct feeds.
    """
    if user is None:
        feeds = FeedModel.query(projection=["link", "etag", "modified"], distinct=distinct)
    else:
        feeds = FeedModel.query(FeedModel.user == user)

    return [f.link for f in feeds]
Ejemplo n.º 2
0
def get_feedurls(user=None, distinct=False):
    '''
    Return a user's distinct feeds. If no user is specified,
    returns all distinct feeds.
    '''
    if user is None:
        feeds = FeedModel.query(projection=["link", "etag", "modified"],
                                distinct=distinct)
    else:
        feeds = FeedModel.query(FeedModel.user == user)

    return [f.link for f in feeds]
Ejemplo n.º 3
0
def put_feed(url, user, title=None, description=None, tag=None):
    if title is None:
        title = domain_from_url(url)
    if description is None:
        description = ""

    feed = FeedModel(key=FeedModelKey(user, url),
                     user=user,
                     timestamp=datetime_now(),
                     title=title,
                     description=description,
                     link=url,
                     tag=tag)

    feed.put()

    return feed_from_model(feed)
Ejemplo n.º 4
0
def get_feed(url):
    result = None
    feeds = FeedModel.query(FeedModel.link == url)
    for feed in feeds:
        result = feed
        break

    return result
Ejemplo n.º 5
0
def get_feed(url):
    result = None
    feeds = FeedModel.query(FeedModel.link == url)
    for feed in feeds:
        result = feed
        break

    return result
Ejemplo n.º 6
0
def put_feed(url, user, title=None, description=None, tag=None):
    if title is None:
        title = domain_from_url(url)
    if description is None:
        description = ""

    feed = FeedModel(
        key=FeedModelKey(user, url),
        user=user,
        timestamp=datetime_now(),
        title=title,
        description=description,
        link=url,
        tag=tag,
    )

    feed.put()

    return feed_from_model(feed)
Ejemplo n.º 7
0
    def _cache_feed(self, url, etag=None, modified=None, tag=None):
            '''
            Caches a feed to the database.

            url can be either a string or a feedmodel.

            '''
            if not "://" in url:
                url = "http://" + url

            # Parse the result
            rss = fp.parse(url, etag=etag, modified=modified)
            #if "etag" in rss:
            #    print("etag:", rss.etag)
            #if "modified" in rss:
            #    print("modified:", rss.modified)
            f = rss.feed
            # If feed does not have title, which is a required attribute,
            # we skip it.
            if not hasattr(f, "title"):
                try:
                    print(rss.debug_message)
                except:
                    pass
                return

            # If no items, move on
            if len(rss.entries) == 0:
                print("No new items, ignoring {}".format(f.title))
                return

            # Update feed last
            timestamp = datetime_now()

            # Get individual items
            any_new_items = False
            for item in rss.entries:
                feeditem = get_feeditem_model(url, timestamp, item)
                # Ignores existing items
                if feeditem is not None:
                    any_new_items = True
                    feeditem.put()
                #else:
                #    print("Ignoring existing feeditem")

            # Only update feed if any new items were retrieved
            if any_new_items:
                feeds = FeedModel.query((FeedModel.link == url))
                for feed in feeds:
                    # Update fields
                    feed.timestamp = timestamp
                    feed.description = f.get("description", "")
                    # Don't override user's own title
                    #feed.title = f.title
                    feed.published = datetuple_to_string(f.get("published_parsed", None))
                    feed.etag = rss.get("etag", None)
                    feed.modified = rss.get("modified", None)
                    # Save
                    print("Cached:", feed.title)
                    # TODO use put_multi or such
                    feed.put()