-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhp.py
31 lines (21 loc) · 807 Bytes
/
hp.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
import requests
class Hp:
"""HP Class"""
def __init__(self):
self.api_url = "https://hp-api.onrender.com/api/"
def getCharacters(self, service="characters/") -> list:
"""getCharacters"""
response = requests.get(self.api_url + service, params={}, timeout=10)
if response.status_code == 200:
data = response.json()
names = []
for item in data:
names.append(item["name"])
return names
def getCharacter(self, service="character/", characterId=None) -> list:
"""getCharacters"""
api_call = self.api_url + service + characterId
response = requests.get(api_call, params={}, timeout=10)
if response.status_code == 200:
data = response.json()
return data[0]