Skip to content

Commit ae6798b

Browse files
author
BASNETANAMIKA
committed
test_api
1 parent c635469 commit ae6798b

File tree

6 files changed

+30
-0
lines changed

6 files changed

+30
-0
lines changed

Self_Practice_Modules/CSV_thanksgiving/__init__.py

Whitespace-only changes.

Self_Practice_Modules/CSV_thanksgiving/caller_program.py

Whitespace-only changes.

Self_Practice_Modules/Regex.py

Whitespace-only changes.

Self_Practice_Modules/test_api/__init__.py

Whitespace-only changes.

Self_Practice_Modules/test_api/api.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import requests
2+
from typing import List
3+
import collections
4+
5+
Category_Details = collections.namedtuple("Category_Details","category,id,url,title,description")
6+
7+
8+
def search_keyword(keyword:str) -> List[Category_Details]:
9+
response = requests.get(f"https://search.talkpython.fm/api/search?q={keyword}")
10+
print(response.status_code)
11+
results = response.json()
12+
entry = []
13+
for r in results.get('results'):
14+
entry.append(Category_Details(**r))
15+
return entry
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import api
2+
3+
4+
def main():
5+
keyword = input("Enter keyword to search with:")
6+
print(f'searching for keyword {keyword}')
7+
results = api.search_keyword(keyword)
8+
9+
print(f'There are {len(results)} results found.')
10+
for r in results:
11+
print(f'title: {r.title} falls under category: {r.category}')
12+
13+
14+
if __name__ == '__main__':
15+
main()

0 commit comments

Comments
 (0)