# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# ## Movies Data
# ---

import pandas as pd
import requests
import json
import string
from datetime import datetime

# +
movies_data = open('/Users/margueriteroth/repos/stu/src/components/Movies/movies.csv')

from csv import reader

read_movies_data = reader(movies_data)
movies = list(read_movies_data)

headers = movies[0]
movies = movies[1:]

print("Headers: ", headers)
print(movies[:10])
# -

# ### Nix the empty column used for the sparkline
# ---

print(headers)
print(len(headers))

while("" in headers):
    headers.remove("")

print(headers)
print(len(headers))

for row in movies:
    row.remove("")

# ### Nix placeholder rows
# ---

# +
movies_clean = []

for row in movies:
    if row[0]:
        movies_clean.append(row)
            
for row in movies_clean:
     print(row)


# +
def urlify(in_string):
    return "%20".join(in_string.split())

def jprint(obj):
    # create a formatted string of the Python JSON object
    text = json.dumps(obj, sort_keys=True, indent=4)
    print(text)



# +
# Snag extra basic info

test_films = []
test_films.append(movies_clean[0])
test_films.append(movies_clean[1])

new_cols = ['tmdb_id', 'overview', 'poster_path', 'year']
for col in new_cols:
    headers.append(col)

    
movies_plus_ids_years = []

test_movies = movies_clean[:5]

for movie in movies_clean:
    title = movie[1]
    title =  ''.join(l for l in title if l not in string.punctuation)
    movie_string = urlify(title)
   
    key = "215a34862d044fe0ee48939851b17bc9"
    url = "https://api.themoviedb.org/3/search/movie?api_key=" + key + "&language=en-US&include_adult=false&query=" + movie_string
    
    film = requests.get(url)
    film = film.json()
    
    film_index = 0
    
    # For now, override to snag correct movie
    if title == 'Dragon Blade' or 'The Stepford Wives':
        film_index = 1
    
    film_id = film['results'][film_index]['id']
    film_year = film['results'][film_index]['release_date']
    film_year = datetime.strptime(film_year, "%Y-%m-%d").year
    
    movie_update = movie
    movie_update.append(film_id)
    movie_update.append(film_year)
    
    print(movie_update)
    print('\n')

    movies_plus_ids_years.append(movie_update)



#jprint(response.json())
# -



















StarcoderdataJupyterScriptsDedupFiltered