File size: 755 Bytes
188ab1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from parser import Article


def sort_by_date(articles):
    return sorted(articles, key=lambda x: x.publishedAt, reverse=True)


def sort_by_upvotes(articles):
    return sorted(articles, key=lambda x: x.paper.upvotes, reverse=True)


def sort_by_comments(articles):
    return sorted(articles, key=lambda x: x.numComments, reverse=True)


if __name__ == "__main__":
    from fetch_paper import fetch_papers
    from rich import print

    articles = fetch_papers()

    print("Latest paper:")
    articles = sort_by_date(articles)
    print(articles[0])

    print("Most upvoted paper:")
    articles = sort_by_upvotes(articles)
    print(articles[0])

    print("Most commented paper:")
    articles = sort_by_comments(articles)
    print(articles[0])