feat: 🎉 Rating Orama!

This commit is contained in:
2023-04-09 06:45:27 +02:00
commit b2f4b573f3
61 changed files with 8130 additions and 0 deletions
+9
View File
@@ -0,0 +1,9 @@
FROM python:3.11.3-alpine
LABEL authors="Pedro Pérez"
COPY requirements.txt requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["python", "main.py"]
View File
+34
View File
@@ -0,0 +1,34 @@
import imdb
from models.tv_show import TVShow, Episode
ia = imdb.Cinemagoer()
def get_tv_show_episodes(tt_id):
tv_show_episodes = ia.get_movie(tt_id)
ia.update(tv_show_episodes, 'episodes')
runtime = tv_show_episodes['runtimes'][0] if 'runtimes' in tv_show_episodes else 0
tv_show = TVShow(tv_show_episodes.getID(), tv_show_episodes['original title'], runtime)
episodes = []
for season in tv_show_episodes['episodes']:
for episode in tv_show_episodes['episodes'][season]:
one_episode = Episode(
tv_show_episodes['episodes'][season][episode].getID(),
tv_show_episodes['episodes'][season][episode].get('title', "#{}.{}".format(season, episode)),
tv_show_episodes['episodes'][season][episode].get('episode', episode),
tv_show_episodes['episodes'][season][episode].get('original air date', 0),
tv_show_episodes['episodes'][season][episode].get('rating', 0),
tv_show_episodes['episodes'][season][episode].get('votes', 0),
tv_show_episodes['episodes'][season][episode].get('season', season))
episodes.append(one_episode.to_dict())
tv_show.add_episodes(episodes)
return tv_show
+16
View File
@@ -0,0 +1,16 @@
from flask import Flask
from routes.ping import ping
from routes.tv_show_routes import tv_show_bp
app = Flask(__name__)
app.register_blueprint(tv_show_bp)
app.register_blueprint(ping)
version = '0.1.0'
appName = 'Rating Orama Harvester'
author = 'Pedro Pérez'
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
View File
+9
View File
@@ -0,0 +1,9 @@
class Movie:
def __init__(self, tt_movie_id, title, year, avg_rating, votes, popularity, runtime):
self.tt_movie_id = tt_movie_id
self.title = title
self.year = year
self.avg_rating = avg_rating
self.votes = votes
self.popularity = popularity
self.runtime = runtime
+39
View File
@@ -0,0 +1,39 @@
class TVShow:
def __init__(self, tt_show_id, title, runtime):
self.tt_show_id = tt_show_id
self.title = title
self.runtime = runtime
self.episodes = []
def add_episodes(self, episodes):
self.episodes = episodes
def to_dict(self):
return {
'tt_show_id': self.tt_show_id,
'title': self.title,
'runtime': self.runtime,
'episodes': [episode.to_dict() for episode in self.episodes]
}
class Episode:
def __init__(self, tt_episode_id, title, number, aired, avg_rating, votes, season_id):
self.tt_episode_id = tt_episode_id
self.title = title
self.number = number
self.aired = aired
self.avg_rating = avg_rating
self.votes = votes
self.season_id = season_id
def to_dict(self):
return {
'tt_episode_id': self.tt_episode_id,
'title': self.title,
'number': self.number,
'aired': self.aired,
'avg_rating': self.avg_rating,
'votes': self.votes,
'season_id': self.season_id
}
+2
View File
@@ -0,0 +1,2 @@
Flask==2.2.3
cinemagoer==2022.12.27
View File
+8
View File
@@ -0,0 +1,8 @@
from flask import jsonify, Blueprint
ping = Blueprint('ping', __name__)
@ping.route('/ping', methods=['GET'])
def ping_pong():
return jsonify('pong!')
+14
View File
@@ -0,0 +1,14 @@
from flask import Blueprint, jsonify
from logic.utils import get_tv_show_episodes
tv_show_bp = Blueprint('tv_show_bp', __name__)
@tv_show_bp.route('/tv-show/<tt_id>', methods=['GET'])
def get_tv_show(tt_id):
try:
tv_show = get_tv_show_episodes(tt_id)
return jsonify(tv_show.__dict__)
except Exception as e:
return jsonify({'error': str(e)}), 500