-
-
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
Merged
Merged
Get top 10 HN posts #5604
Changes from 12 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
cbc74e5
updating DIRECTORY.md
f4264a7
Merge branch 'TheAlgorithms:master' into master
FirePing32 def3bf6
updating DIRECTORY.md
9cec6fc
Create get_top_hn_posts.py
FirePing32 c69cd40
updating DIRECTORY.md
36794a6
Add return type and desc
FirePing32 84657be
Merge branch 'master' into hn-posts
FirePing32 b94c541
Add texttable
FirePing32 704856a
Update web_programming/get_top_hn_posts.py
FirePing32 dc822cd
Update web_programming/get_top_hn_posts.py
FirePing32 2f1a5cf
Get top 10 posts
FirePing32 78abd6b
Update get_top_hn_posts.py
FirePing32 db1682f
Don't use texttable
FirePing32 836a784
Setup doctest
FirePing32 5aac414
Fix pre-commit issues
FirePing32 0607d97
Remove print statement
FirePing32 77922ca
Add hackernews_top_stories_as_markdown()
cclauss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ sklearn | |
statsmodels | ||
sympy | ||
tensorflow | ||
texttable | ||
tweepy | ||
types-requests | ||
xgboost |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import requests | ||
from texttable import Texttable | ||
|
||
|
||
def hackernews_top_stories(max_stories: int = 10) -> dict: | ||
FirePing32 marked this conversation as resolved.
Show resolved
Hide resolved
FirePing32 marked this conversation as resolved.
Show resolved
Hide resolved
FirePing32 marked this conversation as resolved.
Show resolved
Hide resolved
FirePing32 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Get the top 10 posts from HackerNews and display | ||
them as a table inside the terminal | ||
https://news.ycombinator.com/ | ||
""" | ||
|
||
top_stories = "https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty" | ||
|
||
top_10 = requests.get(top_stories).json()[:max_stories] | ||
|
||
table_data = [ | ||
["Title", "URL"], | ||
] | ||
|
||
for story_id in top_10: | ||
story_url = ( | ||
f"https://hacker-news.firebaseio.com/v0/item/{story_id}.json?print=pretty" | ||
) | ||
story_content = requests.get(story_url).json() | ||
content = [story_content["title"], story_content["url"]] | ||
table_data.append(content) | ||
|
||
table = Texttable() | ||
table.set_cols_dtype(["t", "a"]) | ||
table.add_rows(table_data) | ||
print(table.draw()) | ||
|
||
|
||
if __name__ == "__main__": | ||
hackernews_top_stories() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 ?