File tree Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Original file line number Diff line number Diff line change 1
1
import requests
2
- from texttable import Texttable
3
2
4
3
5
- def hackernews_top_stories (max_stories : int = 10 ) -> dict :
4
+ def hackernews_top_stories (max_stories : int = 10 ) -> list :
6
5
"""
7
6
Get the top 10 posts from HackerNews and display
8
7
them as a table inside the terminal
@@ -13,9 +12,7 @@ def hackernews_top_stories(max_stories: int = 10) -> dict:
13
12
14
13
top_10 = requests .get (top_stories ).json ()[:max_stories ]
15
14
16
- table_data = [
17
- ["Title" , "URL" ],
18
- ]
15
+ table_data = []
19
16
20
17
for story_id in top_10 :
21
18
story_url = (
@@ -25,10 +22,10 @@ def hackernews_top_stories(max_stories: int = 10) -> dict:
25
22
content = [story_content ["title" ], story_content ["url" ]]
26
23
table_data .append (content )
27
24
28
- table = Texttable ()
29
- table . set_cols_dtype ([ "t" , "a" ] )
30
- table . add_rows ( table_data )
31
- print ( table . draw ())
25
+ for row in table_data :
26
+ print ( f" { '-' * 150 } \n | { row [ 0 ] } \n | { row [ 1 ] } " )
27
+
28
+ return table_data
32
29
33
30
34
31
if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments