Spaces:
Sleeping
Sleeping
Moiz
commited on
Commit
·
65575bf
1
Parent(s):
c1b881b
added poster links
Browse files- .gitignore +1 -0
- MovieDatabase.csv +0 -0
- database.py +7 -6
.gitignore
CHANGED
@@ -1,3 +1,4 @@
|
|
1 |
.DS_Store
|
2 |
.env
|
3 |
.DS_Store
|
|
|
|
1 |
.DS_Store
|
2 |
.env
|
3 |
.DS_Store
|
4 |
+
MovieDatabase.csv
|
MovieDatabase.csv
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
database.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import requests
|
2 |
import pandas as pd
|
3 |
import os
|
|
|
4 |
|
5 |
# Load CSV
|
6 |
try:
|
@@ -14,7 +15,7 @@ except FileNotFoundError:
|
|
14 |
column_names = [
|
15 |
"id", "Title", "Year", "Rated", "Runtime", "Genre1", "Genre2", "Genre3",
|
16 |
"Director", "Writer", "Plot", "Awards", "IMDb", "Rotten Tomatoes",
|
17 |
-
"Metascore", "IMDb_votes", "Type", "BoxOffice" #
|
18 |
]
|
19 |
database = pd.DataFrame(columns=column_names)
|
20 |
|
@@ -30,8 +31,7 @@ def get_movie(movie_id):
|
|
30 |
if data.get("Response") == "True":
|
31 |
# Extract genres
|
32 |
genres = (data.get("Genre") or "").split(", ")
|
33 |
-
genre1, genre2, genre3 = genres[:3] if len(genres) >= 3 else genres + [None] * (3 - len(genres)
|
34 |
-
)
|
35 |
# Append the movie data to the DataFrame
|
36 |
database.loc[len(database)] = [
|
37 |
movie_id,
|
@@ -50,6 +50,7 @@ def get_movie(movie_id):
|
|
50 |
data.get("imdbVotes"),
|
51 |
data.get("Type"),
|
52 |
data.get("BoxOffice"),
|
|
|
53 |
]
|
54 |
else:
|
55 |
print(f"Error in API response for movie_id {movie_id}: {data.get('Error')}")
|
@@ -58,12 +59,12 @@ def get_movie(movie_id):
|
|
58 |
except Exception as e:
|
59 |
print(f"Exception occurred for movie_id {movie_id}: {e}")
|
60 |
|
61 |
-
# Loop through movie IDs in the CSV and fetch details
|
62 |
-
for i in range(len(df)):
|
63 |
movie_id = df.iloc[i, 0]
|
64 |
get_movie(movie_id)
|
65 |
|
66 |
# Save the DataFrame to a CSV file
|
67 |
-
output_file = '/Users/moizpro/Desktop/MoviesRecommender/MovieRecommender'
|
68 |
database.to_csv(output_file, index=False)
|
69 |
print(f"Movie database saved to {output_file}")
|
|
|
1 |
import requests
|
2 |
import pandas as pd
|
3 |
import os
|
4 |
+
from tqdm import tqdm # Import tqdm for progress bar
|
5 |
|
6 |
# Load CSV
|
7 |
try:
|
|
|
15 |
column_names = [
|
16 |
"id", "Title", "Year", "Rated", "Runtime", "Genre1", "Genre2", "Genre3",
|
17 |
"Director", "Writer", "Plot", "Awards", "IMDb", "Rotten Tomatoes",
|
18 |
+
"Metascore", "IMDb_votes", "Type", "BoxOffice", "Poster" # Add Musab, Moiz, Udisha columns for personal rating if needed
|
19 |
]
|
20 |
database = pd.DataFrame(columns=column_names)
|
21 |
|
|
|
31 |
if data.get("Response") == "True":
|
32 |
# Extract genres
|
33 |
genres = (data.get("Genre") or "").split(", ")
|
34 |
+
genre1, genre2, genre3 = genres[:3] if len(genres) >= 3 else genres + [None] * (3 - len(genres))
|
|
|
35 |
# Append the movie data to the DataFrame
|
36 |
database.loc[len(database)] = [
|
37 |
movie_id,
|
|
|
50 |
data.get("imdbVotes"),
|
51 |
data.get("Type"),
|
52 |
data.get("BoxOffice"),
|
53 |
+
data.get("Poster"),
|
54 |
]
|
55 |
else:
|
56 |
print(f"Error in API response for movie_id {movie_id}: {data.get('Error')}")
|
|
|
59 |
except Exception as e:
|
60 |
print(f"Exception occurred for movie_id {movie_id}: {e}")
|
61 |
|
62 |
+
# Loop through movie IDs in the CSV and fetch details with a progress bar
|
63 |
+
for i in tqdm(range(len(df)), desc="Fetching movie details", unit="movie"):
|
64 |
movie_id = df.iloc[i, 0]
|
65 |
get_movie(movie_id)
|
66 |
|
67 |
# Save the DataFrame to a CSV file
|
68 |
+
output_file = '/Users/moizpro/Desktop/MoviesRecommender/MovieRecommender/MovieDatabase.csv'
|
69 |
database.to_csv(output_file, index=False)
|
70 |
print(f"Movie database saved to {output_file}")
|