-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Adds command to check top hackernews stories #3841
Merged
Merged
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
f70b60d
fix(docs): added margin between sections
jose-donato 4d72f4a
Merge branch 'main' of github.com:GamestonkTerminal/GamestonkTerminal…
jose-donato cb806f4
Merge branch 'main' of github.com:GamestonkTerminal/GamestonkTerminal
jose-donato 59a01f8
Merge branch 'main' of github.com:GamestonkTerminal/GamestonkTerminal
jose-donato 1c48624
Merge branch 'main' of github.com:GamestonkTerminal/GamestonkTerminal…
jose-donato a1fb9f6
Merge branch 'main' of github.com:GamestonkTerminal/GamestonkTerminal
jose-donato 39c7bce
Merge branch 'main' of github.com:GamestonkTerminal/GamestonkTerminal…
jose-donato 72cdc09
Merge branch 'main' of github.com:GamestonkTerminal/GamestonkTerminal
jose-donato c58cf67
Merge branch 'main' of github.com:GamestonkTerminal/GamestonkTerminal…
jose-donato 5ef060a
Merge branch 'main' of github.com:GamestonkTerminal/GamestonkTerminal
jose-donato 74fd42f
Merge branch 'main' of github.com:GamestonkTerminal/GamestonkTerminal…
jose-donato d9af923
Merge branch 'main' of github.com:GamestonkTerminal/GamestonkTerminal
jose-donato 7878a74
Merge branch 'main' of github.com:GamestonkTerminal/GamestonkTerminal…
jose-donato bea6e41
Merge branch 'main' of github.com:GamestonkTerminal/GamestonkTerminal
jose-donato 38e6d18
Merge branch 'main' of github.com:GamestonkTerminal/GamestonkTerminal…
jose-donato 0f02fbc
Merge branch 'main' of github.com:GamestonkTerminal/GamestonkTerminal
jose-donato 2f2ace5
Merge branch 'main' of github.com:GamestonkTerminal/GamestonkTerminal
jose-donato 49e575e
Merge branch 'main' of github.com:GamestonkTerminal/GamestonkTerminal
jose-donato b91c014
Merge branch 'main' of github.com:GamestonkTerminal/GamestonkTerminal
jose-donato ecdd7da
Merge branch 'main' of github.com:GamestonkTerminal/GamestonkTerminal…
jose-donato 03bd5d5
Merge branch 'main' of github.com:GamestonkTerminal/GamestonkTerminal
jose-donato e90aa22
Merge branch 'main' of github.com:GamestonkTerminal/GamestonkTerminal
jose-donato 1f49b58
feat: added hn command
jose-donato 8f1e686
fix: added log decorator
jose-donato 809eede
Merge branch 'main' into hackernews
jmaslek 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 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 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,38 @@ | ||
"""HackerNews Model""" | ||
__docformat__ = "numpy" | ||
|
||
|
||
import logging | ||
import pandas as pd | ||
import requests | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def get_stories(limit: int = 10) -> pd.DataFrame: | ||
"""Get top stories from HackerNews. | ||
Parameters | ||
---------- | ||
limit: int | ||
Number of stories to return | ||
Returns | ||
------- | ||
pd.DataFrame | ||
DataFrame with stories | ||
""" | ||
|
||
res = requests.get("https://hacker-news.firebaseio.com/v0/topstories.json") | ||
if res.status_code == 200: | ||
top_stories = res.json() | ||
stories = [] | ||
for story_id in top_stories[:limit]: | ||
story = requests.get( | ||
f"https://hacker-news.firebaseio.com/v0/item/{story_id}.json" | ||
).json() | ||
stories.append(story) | ||
df = pd.DataFrame(stories) | ||
df["time"] = pd.to_datetime(df["time"], unit="s") | ||
df = df[["title", "url", "score", "type", "time"]] | ||
return df | ||
return pd.DataFrame() |
This file contains 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,31 @@ | ||
"""HackerNews view""" | ||
__docformat__ = "numpy" | ||
|
||
import logging | ||
import os | ||
|
||
from openbb_terminal.alternative.hackernews_model import get_stories | ||
from openbb_terminal.decorators import log_start_end | ||
from openbb_terminal.helper_funcs import ( | ||
export_data, | ||
print_rich_table, | ||
) | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@log_start_end(log=logger) | ||
def display_stories(limit: int = 10, export: str = "") -> None: | ||
"""View top stories from HackerNews. | ||
Parameters | ||
---------- | ||
limit: int | ||
Number of stories to return | ||
export: str | ||
Export dataframe data to csv,json,xlsx file | ||
""" | ||
df = get_stories(limit) | ||
if not df.empty: | ||
df.columns = [col.capitalize() for col in df.columns] | ||
print_rich_table(df, title="HackerNews Top Stories") | ||
export_data(export, os.path.dirname(os.path.abspath(__file__)), "hn", df) |
This file contains 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 |
---|---|---|
|
@@ -508,6 +508,7 @@ | |
"rs": ["GitHub"], | ||
"sh": ["GitHub"], | ||
"tr": ["GitHub"] | ||
} | ||
}, | ||
"hn": ["HackerNews"] | ||
} | ||
} |
This file contains 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 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
Oops, something went wrong.
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.
you should add the log_start_end decorator here