コード例 #1
0
ファイル: services.py プロジェクト: nelf450/cs235A2
def get_articles_by_id(id_list, repo: AbstractRepository):
    articles = repo.get_articles_by_id(id_list)

    # Convert Articles to dictionary form.
    articles_as_dict = articles_to_dict(articles)

    return articles_as_dict
コード例 #2
0
ファイル: services.py プロジェクト: nelf450/cs235A2
def get_random_articles(quantity, repo: AbstractRepository):
    article_count = repo.get_number_of_articles()

    if quantity >= article_count:
        # Reduce the quantity of ids to generate if the repository has an insufficient number of articles.
        quantity = article_count - 1

    # Pick distinct and random articles.
    random_ids = random.sample(range(1, article_count), quantity)
    articles = repo.get_articles_by_id(random_ids)

    return articles_to_dict(articles)