Spaces:
Runtime error
Runtime error
Download sorter.py from SmartFlowAI/HuggingFaceWeeklyPaper: direct link, hf CLI and curl.
- Browser
- Download file 806 Bytes
-
https://huggingface.co/spaces/SmartFlowAI/HuggingFaceWeeklyPaper/resolve/main/sorter.py
- Command line
-
hf download hf://spaces/SmartFlowAI/HuggingFaceWeeklyPaper/sorter.py
-
curl -L -o sorter.py https://huggingface.co/spaces/SmartFlowAI/HuggingFaceWeeklyPaper/resolve/main/sorter.py
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]) | |