Skip to content

Commit

Permalink
Adicao da funcao procurar por videos
Browse files Browse the repository at this point in the history
  • Loading branch information
Jauzimm committed Aug 21, 2024
1 parent 7fbef14 commit 2d67774
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/recommendation_model/utils/get_videos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import requests
import re
from typing import List
import pandas as pd
import string

from utils.model import IVideo

from utils.constants import *

# Função para buscar todos os vídeos
def find_all_videos() -> List[IVideo]:
HEADERS = {"clientkey": EDUPLAY_CLIENT_KEY}

params = {
"institution": UNB_ID,
"limit": VIDEOS_LIMIT,
"order": VIDEOS_ORDER
}

try:
response = requests.get(f"{EDUPLAY_API_URL}video", headers=HEADERS, params=params)
response.raise_for_status()
videos_data = response.json()

# print("Resposta da API:", videos_data)

# Acesse a lista de vídeos
video_list = videos_data.get('videoList', [])

# Filtra vídeos pelo canal da UNB_TV
filtered_videos = [video for video in video_list if video.get('channels') and video['channels'][0]['id'] == UNB_TV_CHANNEL_ID]

return [IVideo(video['id'], video['title'], video.get('description', '')) for video in filtered_videos]
except requests.HTTPError as err:
print(f"Erro ao acessar a API: {err}")
return []
except ValueError as err:
print(f"Erro ao processar o JSON: {err}")
return []

0 comments on commit 2d67774

Please sign in to comment.