-
Notifications
You must be signed in to change notification settings - Fork 4
/
models.py
51 lines (42 loc) · 1.68 KB
/
models.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
import requests
import json
from Enums import Position
from Enums import Status
class Team:
def __init__(self, args):
self.id = int(args["id"])
self.name = str(args["nome"])
self.nick = str(args["abreviacao"])
self.position = int(args["posicao"] if "posicao" in args else -1)
class Score:
def __init__(self, args):
self.turn = int(args["rodada_id"])
self.point = float(args["pontos"])
self.average = float(args["media"])
class Athlete:
def __init__(self, args, teams):
self.id = int(args["atleta_id"])
self.name = str(args["nome"])
self.nick = str(args["apelido"])
self.club = teams[args["clube_id"]]
self.position = Position(int(args["posicao_id"]))
self.status = Status(args["status_id"])
self.points = float(args["pontos_num"])
self.price = float(args["preco_num"])
self.variation = float(args["variacao_num"])
self.average = float(args["media_num"])
self.games = int(args["jogos_num"])
self.turn = int(args["rodada_id"])
self.score = None
def get_scores(self, auth):
if self.score is None:
headers = {'x-glb-token': auth}
url = "https://api.cartolafc.globo.com/auth/mercado/atleta/" + str(self.id) + "/pontuacao"
response = requests.get(url, headers=headers)
scores = json.loads(response.content)
self.score = [Score(score) for score in scores if score["pontos"] is not None]
return self.score
def get_row(self, auth):
print("\tGetting score of " + self.name)
self.get_scores(auth)
return [score.point for score in self.score]