File size: 806 Bytes
188ab1e ccb6afe 188ab1e ccb6afe 188ab1e ccb6afe 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, reverse=True):
return sorted(articles, key=lambda x: x.publishedAt, reverse=reverse)
def sort_by_upvotes(articles, reverse=True):
return sorted(articles, key=lambda x: x.paper.upvotes, reverse=reverse)
def sort_by_comments(articles, reverse=True):
return sorted(articles, key=lambda x: x.numComments, reverse=reverse)
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])
|