def _marshall_group_response(group: DbFeedGroupMetadata): if not group: raise ValueError(group) g = FeedGroupMetadata() g.name = group.name g.last_sync = group.last_sync.isoformat() if group.last_sync else None g.created_at = group.created_at.isoformat() if group.created_at else None g.updated_at = group.last_update.isoformat() if group.last_update else None g.enabled = group.enabled g.record_count = group.count return g.to_dict()
def list_feeds(include_counts=False): """ GET /feeds :return: """ f = DataFeeds.instance() meta = f.list_metadata() response = [] for feed in meta: i = FeedMetadata() i.name = feed.name i.last_full_sync = feed.last_full_sync.isoformat( ) if feed.last_full_sync else None i.created_at = feed.created_at.isoformat() if feed.created_at else None i.updated_at = feed.last_update.isoformat( ) if feed.last_update else None i.groups = [] for group in feed.groups: g = FeedGroupMetadata() g.name = group.name g.last_sync = group.last_sync.isoformat( ) if group.last_sync else None g.created_at = group.created_at.isoformat( ) if group.created_at else None if include_counts: # Compute count (this is slow) g.record_count = f.records_for(i.name, g.name) else: g.record_count = None i.groups.append(g.to_dict()) response.append(i.to_dict()) return jsonify(response)