data and code update.

This commit is contained in:
timothyafolami
2024-11-29 14:59:00 +01:00
parent b7a73606e0
commit 4a0ff6527c
13 changed files with 8665 additions and 1640 deletions
+24 -5
View File
@@ -163,7 +163,7 @@ def product_categorizer(product_lists: list, product_categories=product_categori
return output
def get_youtube_channel_info(channel_name: str):
API_KEY = 'YOUTUBE_API_KEY' # Replace with your API key
API_KEY = YOUTUBE_API_KEY # Replace with your API key
url = 'https://www.googleapis.com/youtube/v3/search'
params = {
@@ -214,7 +214,7 @@ def get_youtube_channel_info(channel_name: str):
def get_channel_videos(channel_name, max_results=5):
try:
API_KEY = 'YOUTUBE_API_KEY'
API_KEY = YOUTUBE_API_KEY
# Build the YouTube service object
youtube = build('youtube', 'v3', developerKey=API_KEY)
@@ -262,8 +262,27 @@ def get_channel_videos(channel_name, max_results=5):
print(f"An HTTP error occurred: {e}")
return []
def get_channel_details(channel_name):
def get_channel_details(channel_name: str):
channel_info = get_youtube_channel_info(channel_name)
recent_videos = get_channel_videos(channel_name)
channel_info['recent_videos'] = recent_videos
return channel_info
# Ensure channel_info is a dictionary
if isinstance(channel_info, dict):
if recent_videos != "No channel found with that name.":
channel_info['recent_videos'] = recent_videos
else:
channel_info['recent_videos'] = "None"
else:
# If channel_info is not a dict, set it to a default structure
channel_info = {
"Title": "Not Found",
"Description": "Channel not found.",
"Subscribers": "NA",
"Total Views": "NA",
"Total Videos": "NA",
"recent_videos": "None"
}
return channel_info
# print(get_channel_details("UCb1j-wdogEnOXXS5B5EhnGg"))