bpHigh commited on
Commit
e092637
1 Parent(s): b968b38

Upload search_recommend.py

Browse files
Files changed (1) hide show
  1. search_recommend.py +40 -0
search_recommend.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from listennotes import podcast_api
2
+ import os
3
+
4
+ api_key = os.environ['LISTENNOTES']
5
+
6
+
7
+ def search(query):
8
+ client = podcast_api.Client(api_key=api_key)
9
+ response = client.search(
10
+ q=query, sort_by_date=1, only_in='title,description', offset=5)
11
+
12
+ results = response.json()
13
+ results_final = results['results']
14
+ final_string = """ """
15
+ number = 1
16
+ for item in results_final:
17
+ final_string += f"{number}"
18
+ number += 1
19
+ final_string += f"RSS:-{item['rss']}\n"
20
+ final_string += f"Title:-{item['title_original']}\n"
21
+ final_string += f"""![{item['title_highlighted']}](item['thumbnail'] "{item['title_original']}") \n\n"""
22
+ recommendations = client.fetch_recommendations_for_podcast(id=item['id'])
23
+ recommendations_json = recommendations.json()
24
+ recommendations_final = recommendations_json["recommendations"]
25
+
26
+ for recommend_item in recommendations_final:
27
+ final_string += f"""![{recommend_item['title']}](recommend_item['image'] "{recommend_item['title']}") \n\n"""
28
+
29
+ return final_string
30
+
31
+
32
+ def search_chat_respond(normal_msg,normal_chatbot):
33
+ response = search(normal_msg)
34
+ normal_chatbot.append((normal_msg,response))
35
+ return "", normal_chatbot
36
+
37
+
38
+
39
+
40
+