Skip to content

Commit

Permalink
Merge pull request #385 from Petsamuel/main
Browse files Browse the repository at this point in the history
resolve movie rater #326
  • Loading branch information
Mrinank-Bhowmick authored Oct 4, 2023
2 parents a494747 + 242deeb commit c181a6c
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 1 deletion.
35 changes: 34 additions & 1 deletion projects/movie-rater/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,37 @@

## Overview

This project is a simple Python API that manages movies and their respective ratings. It serves as a centralized hub for movie enthusiasts to share their opinions, discover new films, and assess the quality of movies they've watched.
This project is a simple Python API that manages movies and their respective ratings. It serves as a centralized hub for movie enthusiasts to share their opinions, discover new films, and assess the quality of movies they've watched.

### Prerequisites

Before you begin, ensure you have met the following requirements:

- [Python](https://www.python.org/downloads/) (version 3.3.0 and above)
- [Pip](https://pip.pypa.io/en/stable/installation/)
- [Virtual Environment](https://docs.python.org/3/library/venv.html) (recommended)

### Installation

1. ## Clone the repository:

```bash
git clone https://github.com/yourusername/your-project.git
cd your-project
```
2. ## Create and activate a virtual environment (optional but recommended):
```python -m venv venv
source venv/bin/activate # On Windows, use venv\Scripts\activate
```
3. ## Install the project dependencies:
```
pip install -r requirements.txt

```
4. ## Running the Application
### To run the FastAPI application, use the following command:

```
uvicorn main:app --reload

```
59 changes: 59 additions & 0 deletions projects/movie-rater/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

from fastapi import FastAPI, HTTPException
from dotenv import load_dotenv
import os
import requests

load_dotenv()


app= FastAPI (

title="MOVIE RATER API",
description="The MovieRater API is your gateway to a world of cinematic exploration and user-generated movie ratings. This versatile API empowers developers to create dynamic movie-related applications, allowing users to rate, review, and discover films from a vast collection.",
docs_url="/"
)
apiKey=os.getenv("API_KEY")
apiToken=os.getenv("API_TOKEN")



@app.get("/movies")
async def get_popular_movies():
url=f"https://api.themoviedb.org/3/discover/movie?api_key={apiKey}&sort_by=popularity.desc"

response = requests.get(url)
if response.status_code != 200:
raise HTTPException(status_code=response.status_code, detail=response.content)

movie_data = response.json()

return movie_data

@app.get("/movies/{movie_id}")
async def get_movie(movie_id: int):
"""Get information about a movie."""

url = f"https://api.themoviedb.org/3/movie/{movie_id}?api_key={apiKey}"
response = requests.get(url)

if response.status_code != 200:
raise HTTPException(status_code=response.status_code, detail=response.content)

movie_data = response.json()

return movie_data

@app.post("/movies/{movie_id}/rate")
async def rate_movie(movie_id: int, rating: int):
"""Rate a movie."""

# Validate the rating.
if rating not in range(1, 11):
raise HTTPException(status_code=400, detail="Rating must be between 1 and 10.")

# Save the rating to your database.

# Return a success response.
return {"message": "Movie rated successfully."}

17 changes: 17 additions & 0 deletions projects/movie-rater/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
annotated-types==0.5.0
anyio==3.7.1
asyncpg==0.28.0
certifi==2023.7.22
charset-normalizer==3.3.0
fastapi==0.103.2
greenlet==2.0.2
idna==3.4
pydantic==2.4.2
pydantic_core==2.10.1
python-dotenv==1.0.0
requests==2.31.0
sniffio==1.3.0
SQLAlchemy==2.0.21
starlette==0.27.0
typing_extensions==4.8.0
urllib3==2.0.5

0 comments on commit c181a6c

Please sign in to comment.