HowardZhangdqs's picture
懒得写commit了
ccb6afe
raw
history blame contribute delete
806 Bytes
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])