File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 5353## Cellular Automata
5454 * [ Conways Game Of Life] ( https://github.com/TheAlgorithms/Python/blob/master/cellular_automata/conways_game_of_life.py )
5555 * [ Game Of Life] ( https://github.com/TheAlgorithms/Python/blob/master/cellular_automata/game_of_life.py )
56+ * [ Nagel Schrekenberg] ( https://github.com/TheAlgorithms/Python/blob/master/cellular_automata/nagel_schrekenberg.py )
5657 * [ One Dimensional] ( https://github.com/TheAlgorithms/Python/blob/master/cellular_automata/one_dimensional.py )
5758
5859## Ciphers
987988 * [ Fetch Jobs] ( https://github.com/TheAlgorithms/Python/blob/master/web_programming/fetch_jobs.py )
988989 * [ Get Imdb Top 250 Movies Csv] ( https://github.com/TheAlgorithms/Python/blob/master/web_programming/get_imdb_top_250_movies_csv.py )
989990 * [ Get Imdbtop] ( https://github.com/TheAlgorithms/Python/blob/master/web_programming/get_imdbtop.py )
991+ * [ Get Top Hn Posts] ( https://github.com/TheAlgorithms/Python/blob/master/web_programming/get_top_hn_posts.py )
990992 * [ Get User Tweets] ( https://github.com/TheAlgorithms/Python/blob/master/web_programming/get_user_tweets.py )
991993 * [ Giphy] ( https://github.com/TheAlgorithms/Python/blob/master/web_programming/giphy.py )
992994 * [ Instagram Crawler] ( https://github.com/TheAlgorithms/Python/blob/master/web_programming/instagram_crawler.py )
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ sklearn
1414statsmodels
1515sympy
1616tensorflow
17+ texttable
1718tweepy
1819types-requests
1920xgboost
Original file line number Diff line number Diff line change 1+ from __future__ import annotations
2+
3+ import requests
4+
5+
6+ def get_hackernews_story (story_id : str ) -> dict :
7+ url = f"https://hacker-news.firebaseio.com/v0/item/{ story_id } .json?print=pretty"
8+ return requests .get (url ).json ()
9+
10+
11+ def hackernews_top_stories (max_stories : int = 10 ) -> list [dict ]:
12+ """
13+ Get the top max_stories posts from HackerNews - https://news.ycombinator.com/
14+ """
15+ url = "https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty"
16+ story_ids = requests .get (url ).json ()[:max_stories ]
17+ return [get_hackernews_story (story_id ) for story_id in story_ids ]
18+
19+
20+ def hackernews_top_stories_as_markdown (max_stories : int = 10 ) -> str :
21+ stories = hackernews_top_stories (max_stories )
22+ return "\n " .join ("* [{title}]({url})" .format (** story ) for story in stories )
23+
24+
25+ if __name__ == "__main__" :
26+ print (hackernews_top_stories_as_markdown ())
You can’t perform that action at this time.
0 commit comments