File size: 1,257 Bytes
e092637
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from listennotes import podcast_api
import os

api_key = os.environ['LISTENNOTES']


def search(query):
    client = podcast_api.Client(api_key=api_key)
    response = client.search(
        q=query, sort_by_date=1, only_in='title,description', offset=5)

    results = response.json()
    results_final = results['results']
    final_string = """ """
    number = 1
    for item in results_final:
        final_string += f"{number}"
        number += 1
        final_string += f"RSS:-{item['rss']}\n"
        final_string += f"Title:-{item['title_original']}\n"
        final_string += f"""![{item['title_highlighted']}](item['thumbnail'] "{item['title_original']}") \n\n"""
        recommendations = client.fetch_recommendations_for_podcast(id=item['id'])
        recommendations_json = recommendations.json()
        recommendations_final = recommendations_json["recommendations"]

        for recommend_item in recommendations_final:
            final_string += f"""![{recommend_item['title']}](recommend_item['image'] "{recommend_item['title']}") \n\n"""

    return final_string


def search_chat_respond(normal_msg,normal_chatbot):
    response = search(normal_msg)
    normal_chatbot.append((normal_msg,response))
    return "", normal_chatbot