File size: 1,852 Bytes
e092637
 
6777004
e092637
 
 
 
 
 
 
4966db5
e092637
 
 
 
 
 
bd070c6
 
4966db5
e092637
635fb60
165dc19
cd91358
e092637
 
6777004
 
 
 
 
 
 
 
 
5a5b7ef
 
6777004
 
 
 
 
e092637
6777004
 
 
 
4966db5
6777004
 
 
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from listennotes import podcast_api
import os
import json

api_key = os.environ['LISTENNOTES']


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

    results = response.json()
    results_final = results['results']
    final_string = """ """
    number = 1
    for item in results_final:
        final_string += f"{number}. "
        final_string += f"Podcast ID:-{item['id']}\n"
        final_string += f"Link:-{item['listennotes_url']}\n"
        final_string += f"Title:-{item['title_original']}\n"
        final_string += f"![{item['title_highlighted']}]({item['thumbnail']} '{item['title_original']}')\n\n"
        final_string += "\n\n"
        number += 1
    return final_string

def recommend(podcast_id):
    client = podcast_api.Client(api_key=api_key) 
    response = client.fetch_recommendations_for_podcast(id=podcast_id)
    results = response.json()
    results_final = results["recommendations"]
    final_string = """ """
    number = 1
    for item in results_final:
        final_string += f"{number}. "
        final_string += f"Title:- {item['title']}\n"
        final_string += f"Description:- {item['description']}"
        final_string += f"![{item['title']}]({item['image']} '{item['title']}')\n\n"
        final_string += "\n\n"
        number += 1
    return final_string


def get_podcast_title(podcast_id):
    client = podcast_api.Client(api_key=api_key) 
    response = client.fetch_podcast_by_id(id=podcast_id)
    result = response.json()
    results_final = result["title"]
    return results_final
    
    
def search_chat_respond(normal_msg,normal_chatbot):
    response = search(normal_msg)
    normal_chatbot.append((normal_msg,response))
    return "", normal_chatbot