Skip to content

Commit db1682f

Browse files
authored
Don't use texttable
1 parent 78abd6b commit db1682f

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

web_programming/get_top_hn_posts.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import requests
2-
from texttable import Texttable
32

43

5-
def hackernews_top_stories(max_stories: int = 10) -> dict:
4+
def hackernews_top_stories(max_stories: int = 10) -> list:
65
"""
76
Get the top 10 posts from HackerNews and display
87
them as a table inside the terminal
@@ -13,9 +12,7 @@ def hackernews_top_stories(max_stories: int = 10) -> dict:
1312

1413
top_10 = requests.get(top_stories).json()[:max_stories]
1514

16-
table_data = [
17-
["Title", "URL"],
18-
]
15+
table_data = []
1916

2017
for story_id in top_10:
2118
story_url = (
@@ -25,10 +22,10 @@ def hackernews_top_stories(max_stories: int = 10) -> dict:
2522
content = [story_content["title"], story_content["url"]]
2623
table_data.append(content)
2724

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
3229

3330

3431
if __name__ == "__main__":

0 commit comments

Comments
 (0)