diff --git a/DIRECTORY.md b/DIRECTORY.md index e2b2442fd1b1..67f2113ea87d 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -53,6 +53,7 @@ ## Cellular Automata * [Conways Game Of Life](https://github.com/TheAlgorithms/Python/blob/master/cellular_automata/conways_game_of_life.py) * [Game Of Life](https://github.com/TheAlgorithms/Python/blob/master/cellular_automata/game_of_life.py) + * [Nagel Schrekenberg](https://github.com/TheAlgorithms/Python/blob/master/cellular_automata/nagel_schrekenberg.py) * [One Dimensional](https://github.com/TheAlgorithms/Python/blob/master/cellular_automata/one_dimensional.py) ## Ciphers @@ -944,6 +945,7 @@ * [Capitalize](https://github.com/TheAlgorithms/Python/blob/master/strings/capitalize.py) * [Check Anagrams](https://github.com/TheAlgorithms/Python/blob/master/strings/check_anagrams.py) * [Check Pangram](https://github.com/TheAlgorithms/Python/blob/master/strings/check_pangram.py) + * [Credit Card Validator](https://github.com/TheAlgorithms/Python/blob/master/strings/credit_card_validator.py) * [Detecting English Programmatically](https://github.com/TheAlgorithms/Python/blob/master/strings/detecting_english_programmatically.py) * [Frequency Finder](https://github.com/TheAlgorithms/Python/blob/master/strings/frequency_finder.py) * [Indian Phone Validator](https://github.com/TheAlgorithms/Python/blob/master/strings/indian_phone_validator.py) @@ -961,6 +963,7 @@ * [Rabin Karp](https://github.com/TheAlgorithms/Python/blob/master/strings/rabin_karp.py) * [Remove Duplicate](https://github.com/TheAlgorithms/Python/blob/master/strings/remove_duplicate.py) * [Reverse Letters](https://github.com/TheAlgorithms/Python/blob/master/strings/reverse_letters.py) + * [Reverse Long Words](https://github.com/TheAlgorithms/Python/blob/master/strings/reverse_long_words.py) * [Reverse Words](https://github.com/TheAlgorithms/Python/blob/master/strings/reverse_words.py) * [Split](https://github.com/TheAlgorithms/Python/blob/master/strings/split.py) * [Upper](https://github.com/TheAlgorithms/Python/blob/master/strings/upper.py) @@ -985,6 +988,7 @@ * [Fetch Jobs](https://github.com/TheAlgorithms/Python/blob/master/web_programming/fetch_jobs.py) * [Get Imdb Top 250 Movies Csv](https://github.com/TheAlgorithms/Python/blob/master/web_programming/get_imdb_top_250_movies_csv.py) * [Get Imdbtop](https://github.com/TheAlgorithms/Python/blob/master/web_programming/get_imdbtop.py) + * [Get Top Hn Posts](https://github.com/TheAlgorithms/Python/blob/master/web_programming/get_top_hn_posts.py) * [Get User Tweets](https://github.com/TheAlgorithms/Python/blob/master/web_programming/get_user_tweets.py) * [Giphy](https://github.com/TheAlgorithms/Python/blob/master/web_programming/giphy.py) * [Instagram Crawler](https://github.com/TheAlgorithms/Python/blob/master/web_programming/instagram_crawler.py) diff --git a/requirements.txt b/requirements.txt index 7c2672ae25d3..c28238a0774f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,6 +14,7 @@ sklearn statsmodels sympy tensorflow +texttable tweepy types-requests xgboost diff --git a/web_programming/get_top_hn_posts.py b/web_programming/get_top_hn_posts.py new file mode 100644 index 000000000000..fbb7c051a88e --- /dev/null +++ b/web_programming/get_top_hn_posts.py @@ -0,0 +1,26 @@ +from __future__ import annotations + +import requests + + +def get_hackernews_story(story_id: str) -> dict: + 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]: + """ + 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: + stories = hackernews_top_stories(max_stories) + return "\n".join("* [{title}]({url})".format(**story) for story in stories) + + +if __name__ == "__main__": + print(hackernews_top_stories_as_markdown())