<commit_before># -*- coding: utf-8 -*-

from itertools import ifilterfalse

import feedparser

from model import database, open_database, Feed, Entry


db = database


def open_db(filepath):
    open_database(filepath)
    return db


# entry api for web app

def get_entries_as_dict(count, offset, priority, order):
    return [
        e.to_dict() for e in get_entries(count, offset, priority, order)
    ]


def get_entries(count, offset, priority, order):
    order = getattr(Entry.created_date, order)()
    return Entry.select().join(Feed).where(
        Feed.priority >= priority,
        Entry.is_read == False
    ).order_by(order).offset(offset).limit(count)


def read_entries(id_list):
    Entry.update(is_read=True).where(Entry.id << id_list).execute()


def update_an_entry(id, changed):
    e = Entry.get(id=id)
    for attr, value in changed.items():
        if attr in ['is_read', 'is_liked', 'is_disliked']:  # writable attr
            setattr(e, attr, value)
    e.save()


# feed api for web app

def get_feeds_as_dict():
    return [f.to_dict() for f in get_feeds()]


def get_feeds():
    return Feed.select().order_by(Feed.created_date.desc())


def feed_exists(url):
    return Feed.select().where(Feed.url == url).exists()


def add_a_feed(url):
    if feed_exists(url):
        raise Exception('feed already exists')  # todo: handle error
    feeddata = feedparser.parse(url)  # todo: handle error
    feed = Feed.create(url=feeddata.href, title=feeddata.feed.title)
    return feed.to_dict()


def update_a_feed(id, changed):
    f = Feed.get(id=id)
    for attr, value in changed.items():
        if attr in ['priority', 'is_disabled']:  # writable attr
            setattr(f, attr, value)
    f.save()

<commit_msg>changes to return a list<commit_after># -*- coding: utf-8 -*-

from itertools import ifilterfalse

import feedparser

from model import database, open_database, Feed, Entry


db = database


def open_db(filepath):
    open_database(filepath)
    return db


# entry api for web app

def get_entries_as_dict(count, offset, priority, order):
    return [
        e.to_dict() for e in get_entries(count, offset, priority, order)
    ]


def get_entries(count, offset, priority, order):
    order = getattr(Entry.created_date, order)()
    return list(Entry.select().join(Feed).where(
        Feed.priority >= priority,
        Entry.is_read == False
    ).order_by(order).offset(offset).limit(count))


def read_entries(id_list):
    Entry.update(is_read=True).where(Entry.id << id_list).execute()


def update_an_entry(id, changed):
    e = Entry.get(id=id)
    for attr, value in changed.items():
        if attr in ['is_read', 'is_liked', 'is_disliked']:  # writable attr
            setattr(e, attr, value)
    e.save()


# feed api for web app

def get_feeds_as_dict():
    return [f.to_dict() for f in get_feeds()]


def get_feeds():
    return list(Feed.select().order_by(Feed.created_date.desc()))


def feed_exists(url):
    return Feed.select().where(Feed.url == url).exists()


def add_a_feed(url):
    if feed_exists(url):
        raise Exception('feed already exists')  # todo: handle error
    feeddata = feedparser.parse(url)  # todo: handle error
    feed = Feed.create(url=feeddata.href, title=feeddata.feed.title)
    return feed.to_dict()


def update_a_feed(id, changed):
    f = Feed.get(id=id)
    for attr, value in changed.items():
        if attr in ['priority', 'is_disabled']:  # writable attr
            setattr(f, attr, value)
    f.save()


{'fraction_non_alphanumeric': 0.12923427270139481, 'fraction_numerical': 0.000569313976658127, 'mean_word_length': 3.420125786163522, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7166894', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1159, 'n_words': 298}