-
-
Notifications
You must be signed in to change notification settings - Fork 46.7k
Get top 10 HN posts #5604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get top 10 HN posts #5604
Changes from all commits
cbc74e5
f4264a7
def3bf6
9cec6fc
c69cd40
36794a6
84657be
b94c541
704856a
dc822cd
2f1a5cf
78abd6b
db1682f
836a784
5aac414
0607d97
77922ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ sklearn | |
statsmodels | ||
sympy | ||
tensorflow | ||
texttable | ||
tweepy | ||
types-requests | ||
xgboost |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from __future__ import annotations | ||
|
||
import requests | ||
|
||
|
||
def get_hackernews_story(story_id: str) -> dict: | ||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
url = f"https://hacker-news.firebaseio.com/v0/item/{story_id}.json?print=pretty" | ||
return requests.get(url).json() | ||
|
||
|
||
def hackernews_top_stories(max_stories: int = 10) -> list[dict]: | ||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Get the top max_stories posts from HackerNews - https://news.ycombinator.com/ | ||
""" | ||
url = "https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty" | ||
story_ids = requests.get(url).json()[:max_stories] | ||
return [get_hackernews_story(story_id) for story_id in story_ids] | ||
|
||
|
||
def hackernews_top_stories_as_markdown(max_stories: int = 10) -> str: | ||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
stories = hackernews_top_stories(max_stories) | ||
return "\n".join("* [{title}]({url})".format(**story) for story in stories) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned in the Contributing Guidelines, please do not use printf style formatting or There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
|
||
if __name__ == "__main__": | ||
print(hackernews_top_stories_as_markdown()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not add to our requirements just for a single-use. We are not looking for how-to-use content.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed

texttable
and tried doing it from scratch. Altough I couldn't get the exact same output, but you should see this.I couldn't get a better output than this. Is this okay ?