-
Notifications
You must be signed in to change notification settings - Fork 0
/
Character.py
30 lines (28 loc) · 905 Bytes
/
Character.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
import requests
class Character(object):
def __init__(self, url, name, gender, culture, born, died, titles, aliases, \
father, mother, spouse, allegiances, \
books, povBooks, tvSeries, playedBy):
self.url = url
self.name = name
self.gender = gender
self.culture = culture
self.born = born
self.died = died
self.titles = titles
self.aliases = aliases
self.father = father
self.mother = mother
self.spouse = spouse
self.allegiances = allegiances
self.books = books
self.povBooks = povBooks
self.tvSeries = tvSeries
self.playedBy = playedBy
@classmethod
def fromurl(cls, url):
json = requests.get(url).json()
if (type(json) == dict):
return [cls(*json.values())]
else:
return [cls(*(x.values())) for x in json]