movies box office data
This commit is contained in:
parent
2430e2c879
commit
20bb53b207
@ -159,6 +159,15 @@ def updateCommodities(api_key, logf):
|
|||||||
#logf.close()
|
#logf.close()
|
||||||
|
|
||||||
|
|
||||||
|
def human_format(num):
|
||||||
|
num = float('{:.3g}'.format(num))
|
||||||
|
magnitude = 0
|
||||||
|
while abs(num) >= 1000:
|
||||||
|
magnitude += 1
|
||||||
|
num /= 1000.0
|
||||||
|
return '{}{}'.format('{:f}'.format(num).rstrip('0').rstrip('.'), ['', 'K', 'M', 'B', 'T'][magnitude])
|
||||||
|
|
||||||
|
|
||||||
def updateMovies(api_key, logf):
|
def updateMovies(api_key, logf):
|
||||||
|
|
||||||
f = open('csv/movie_settings.json', 'r')
|
f = open('csv/movie_settings.json', 'r')
|
||||||
@ -198,6 +207,18 @@ def updateMovies(api_key, logf):
|
|||||||
movies = data['results']
|
movies = data['results']
|
||||||
|
|
||||||
for movie in movies:
|
for movie in movies:
|
||||||
|
|
||||||
|
if movie['media_type'] == 'movie':
|
||||||
|
movie_id = movie['id']
|
||||||
|
box_office_url = 'https://api.themoviedb.org/3/movie/' + str(movie_id) + '?api_key=' + api_key
|
||||||
|
box_office_response = requests.get(box_office_url)
|
||||||
|
box_office_data = box_office_response.json()
|
||||||
|
budget = human_format(box_office_data['budget'])
|
||||||
|
revenue = human_format(box_office_data['revenue'])
|
||||||
|
else:
|
||||||
|
budget = '0'
|
||||||
|
revenue = '0'
|
||||||
|
|
||||||
movie_language = movie['original_language']
|
movie_language = movie['original_language']
|
||||||
movie_votes = movie['vote_average']
|
movie_votes = movie['vote_average']
|
||||||
movie_votes = "{:.1f}".format(movie_votes)
|
movie_votes = "{:.1f}".format(movie_votes)
|
||||||
@ -248,13 +269,17 @@ def updateMovies(api_key, logf):
|
|||||||
'date':movie_date,
|
'date':movie_date,
|
||||||
'media_type':movie_type.capitalize(),
|
'media_type':movie_type.capitalize(),
|
||||||
'genre':genrefinal,
|
'genre':genrefinal,
|
||||||
|
'budget':budget,
|
||||||
|
'revenue':revenue,
|
||||||
'backdrop':movie['backdrop_path'][1:],
|
'backdrop':movie['backdrop_path'][1:],
|
||||||
'logo': movie_logo
|
'logo': movie_logo
|
||||||
})
|
})
|
||||||
|
|
||||||
logo_files.append(movie['backdrop_path'][1:])
|
logo_files.append(movie['backdrop_path'][1:])
|
||||||
|
|
||||||
|
if movie['backdrop_path'][1:] not in os.listdir('logos/movies/'):
|
||||||
urllib.request.urlretrieve(movie_logo,'logos/movies/' + movie['backdrop_path'])
|
urllib.request.urlretrieve(movie_logo,'logos/movies/' + movie['backdrop_path'])
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
for file in os.listdir('logos/movies/'):
|
for file in os.listdir('logos/movies/'):
|
||||||
if file not in logo_files:
|
if file not in logo_files:
|
||||||
|
Loading…
Reference in New Issue
Block a user