|
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]) |
|
|