forked from Itope84/star-spotter-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_actor.py
66 lines (51 loc) · 1.85 KB
/
find_actor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import requests
import os
from dotenv import load_dotenv
import boto3
# Load environment variables from .env file
load_dotenv()
rapid_api_key = os.environ.get("RAPID_API_KEY")
def find_actor_by_image(image_file):
# creating a Rekognition client
client = boto3.client('rekognition')
response = client.recognize_celebrities(Image={'Bytes': image_file.read()})
# parsing the response to get the 1st celebrity name
if response['CelebrityFaces']:
actor_name = response['CelebrityFaces'][0]['Name']
return actor_name
else:
return None
def find_actor_id(actor_name):
url = "https://flixster.p.rapidapi.com/search"
querystring = {"query": actor_name}
print(rapid_api_key)
headers = {
"X-RapidAPI-Key": rapid_api_key,
"X-RapidAPI-Host": "flixster.p.rapidapi.com",
}
response = requests.get(url, headers=headers, params=querystring)
data = response.json()
# print(data)
# Extractibg info from the API response
for person in data.get("data", {}).get("search", {}).get("people", []):
if person.get("name") == actor_name:
return person.get("id")
return None
def find_actor_profile(actor_id):
url = "https://flixster.p.rapidapi.com/actors/detail"
querystring = {"id": actor_id}
print(rapid_api_key)
headers = {
"X-RapidAPI-Key": rapid_api_key,
"X-RapidAPI-Host": "flixster.p.rapidapi.com",
}
response = requests.get(url, headers=headers, params=querystring)
data = response.json()
response_profile = data.get("data", {}).get("person", {})
actor_profile = {
"name": response_profile.get("name"),
"birthDate": response_profile.get("birthDate"),
"headShotImage": response_profile.get("headShotImage"),
"filmography": response_profile.get("filmography"),
}
return actor_profile