movies box office data

This commit is contained in:
Justin 2023-02-23 13:18:00 +08:00 committed by GitHub
parent 2430e2c879
commit 20bb53b207
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -158,7 +158,16 @@ def updateCommodities(api_key, logf):
#logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
#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):
f = open('csv/movie_settings.json', 'r')
@ -198,6 +207,18 @@ def updateMovies(api_key, logf):
movies = data['results']
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_votes = movie['vote_average']
movie_votes = "{:.1f}".format(movie_votes)
@ -248,13 +269,17 @@ def updateMovies(api_key, logf):
'date':movie_date,
'media_type':movie_type.capitalize(),
'genre':genrefinal,
'budget':budget,
'revenue':revenue,
'backdrop':movie['backdrop_path'][1:],
'logo': movie_logo
})
logo_files.append(movie['backdrop_path'][1:])
urllib.request.urlretrieve(movie_logo,'logos/movies/' + movie['backdrop_path'])
if movie['backdrop_path'][1:] not in os.listdir('logos/movies/'):
urllib.request.urlretrieve(movie_logo,'logos/movies/' + movie['backdrop_path'])
time.sleep(0.5)
for file in os.listdir('logos/movies/'):
if file not in logo_files: