Skip to content

Commit

Permalink
Merge pull request #51 from vicenteneto/dev
Browse files Browse the repository at this point in the history
Lançando versao 1.4.14
  • Loading branch information
vicenteneto authored Apr 14, 2018
2 parents c2f60ed + b22c933 commit 728ae2c
Show file tree
Hide file tree
Showing 29 changed files with 94 additions and 518 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ cover
Python_CartolaFC.egg-info/
dist/

# Sphinx
docs/build/

# Tox
.tox/

# Helper scripts
deploy.sh
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ language: python

python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
Expand Down
10 changes: 10 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ Changelog

Aqui você pode ver a lista completa de modificações entre cada versão.

Versão 1.4.14
-------------

Lançada em 1 de abril de 2018

- Atualizando projeto exemplo para suportar Python3
- Corrigindo erro ao visualizar Mercado
- Atualizando dependencias


Versão 0.8.13
-------------

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ objetos de python mais convencionais.

## Versões

Este projeto foi testado e funciona em Python 2.7, 3.3, 3.4, 3.5 e 3.6.
Este projeto foi testado e funciona em Python 2.7, 3.4, 3.5 e 3.6.


## Instalação
Expand Down
15 changes: 14 additions & 1 deletion cartolafc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,17 @@
"""

from .api import Api, CAMPEONATO, TURNO, MERCADO_ABERTO, MERCADO_FECHADO, MES, RODADA, PATRIMONIO
from .error import CartolaFCError, CartolaFCOverloadError
from .errors import CartolaFCError, CartolaFCOverloadError

__all__ = [
'Api',
'CAMPEONATO',
'TURNO',
'MERCADO_ABERTO',
'MERCADO_FECHADO',
'MES',
'RODADA',
'PATRIMONIO',
'CartolaFCError',
'CartolaFCOverloadError',
]
10 changes: 5 additions & 5 deletions cartolafc/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

import requests

from cartolafc.decorators import RequiresAuthentication
from cartolafc.error import CartolaFCError, CartolaFCOverloadError
from cartolafc.models import Atleta, Clube, DestaqueRodada, Liga, LigaPatrocinador, Mercado, Partida, PontuacaoInfo
from cartolafc.models import Time, TimeInfo
from cartolafc.util import convert_team_name_to_slug, parse_and_check_cartolafc
from .decorators import RequiresAuthentication
from .errors import CartolaFCError, CartolaFCOverloadError
from .models import Atleta, Clube, DestaqueRodada, Liga, LigaPatrocinador, Mercado, Partida, PontuacaoInfo
from .models import Time, TimeInfo
from .util import convert_team_name_to_slug, parse_and_check_cartolafc

logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)

Expand Down
2 changes: 1 addition & 1 deletion cartolafc/decorators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from cartolafc.error import CartolaFCError
from .errors import CartolaFCError


class RequiresAuthentication(object):
Expand Down
File renamed without changes.
59 changes: 17 additions & 42 deletions cartolafc/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-

import json
from collections import namedtuple
from datetime import datetime

import json
from .util import json_default

Posicao = namedtuple('Posicao', ['id', 'nome', 'abreviacao'])
Status = namedtuple('Status', ['id', 'nome'])
Expand Down Expand Up @@ -34,7 +35,12 @@
}


class Atleta(object):
class BaseModel(object):
def __repr__(self):
return json.dumps(self, default=json_default)


class Atleta(BaseModel):
""" Representa um atleta (jogador ou técnico), e possui informações como o apelido, clube e pontuação obtida """

def __init__(self, atleta_id, apelido, pontos, scout, posicao_id, clube, status_id=None):
Expand All @@ -46,10 +52,6 @@ def __init__(self, atleta_id, apelido, pontos, scout, posicao_id, clube, status_
self.clube = clube
self.status = _atleta_status[status_id] if status_id else None

def __repr__(self):
return json.dumps(self, default=lambda o: o.__dict__)


@classmethod
def from_dict(cls, data, clubes, atleta_id=None):
atleta_id = atleta_id if atleta_id else data['atleta_id']
Expand All @@ -59,40 +61,34 @@ def from_dict(cls, data, clubes, atleta_id=None):
data.get('status_id', None))


class Clube(object):
class Clube(BaseModel):
""" Representa um dos 20 clubes presentes no campeonato, e possui informações como o nome e a abreviação """

def __init__(self, id, nome, abreviacao):
self.id = id
self.nome = nome
self.abreviacao = abreviacao

def __repr__(self):
return json.dumps(self, default=lambda o: o.__dict__)

@classmethod
def from_dict(cls, data):
return cls(data['id'], data['nome'], data['abreviacao'])


class DestaqueRodada(object):
class DestaqueRodada(BaseModel):
""" Destaque Rodada"""

def __init__(self, media_cartoletas, media_pontos, mito_rodada):
self.media_cartoletas = media_cartoletas
self.media_pontos = media_pontos
self.mito_rodada = mito_rodada

def __repr__(self):
return json.dumps(self, default=lambda o: o.__dict__)

@classmethod
def from_dict(cls, data):
mito_rodada = TimeInfo.from_dict(data['mito_rodada'])
return cls(data['media_cartoletas'], data['media_pontos'], mito_rodada)


class Liga(object):
class Liga(BaseModel):
""" Liga """

def __init__(self, liga_id, nome, slug, descricao, times):
Expand All @@ -102,33 +98,27 @@ def __init__(self, liga_id, nome, slug, descricao, times):
self.descricao = descricao
self.times = times

def __repr__(self):
return json.dumps(self, default=lambda o: o.__dict__)

@classmethod
def from_dict(cls, data, ranking=None):
data_liga = data.get('liga', data)
times = [TimeInfo.from_dict(time, ranking=ranking) for time in data['times']] if 'times' in data else None
return cls(data_liga['liga_id'], data_liga['nome'], data_liga['slug'], data_liga['descricao'], times)


class LigaPatrocinador(object):
class LigaPatrocinador(BaseModel):
""" Liga Patrocinador """

def __init__(self, liga_id, nome, url_link):
self.id = liga_id
self.nome = nome
self.url_link = url_link

def __repr__(self):
return json.dumps(self, default=lambda o: o.__dict__)

@classmethod
def from_dict(cls, data):
return cls(data['liga_id'], data['nome'], data['url_link'])


class Mercado(object):
class Mercado(BaseModel):
""" Mercado """

def __init__(self, rodada_atual, status_mercado, times_escalados, aviso, fechamento):
Expand All @@ -138,16 +128,13 @@ def __init__(self, rodada_atual, status_mercado, times_escalados, aviso, fechame
self.aviso = aviso
self.fechamento = fechamento

def __repr__(self):
return json.dumps(self, default=lambda o: o.__dict__)

@classmethod
def from_dict(cls, data):
fechamento = datetime.fromtimestamp(data['fechamento']['timestamp'])
return cls(data['rodada_atual'], data['status_mercado'], data['times_escalados'], data['aviso'], fechamento)


class Partida(object):
class Partida(BaseModel):
""" Partida """

def __init__(self, data, local, clube_casa, placar_casa, clube_visitante, placar_visitante):
Expand All @@ -158,9 +145,6 @@ def __init__(self, data, local, clube_casa, placar_casa, clube_visitante, placar
self.clube_visitante = clube_visitante
self.placar_visitante = placar_visitante

def __repr__(self):
return json.dumps(self, default=lambda o: o.__dict__)

@classmethod
def from_dict(cls, data, clubes):
data_ = datetime.strptime(data['partida_data'], '%Y-%m-%d %H:%M:%S')
Expand All @@ -172,7 +156,7 @@ def from_dict(cls, data, clubes):
return cls(data_, local, clube_casa, placar_casa, clube_visitante, placar_visitante)


class PontuacaoInfo(object):
class PontuacaoInfo(BaseModel):
""" Pontuação Info """

def __init__(self, atleta_id, rodada_id, pontos, preco, variacao, media):
Expand All @@ -183,15 +167,12 @@ def __init__(self, atleta_id, rodada_id, pontos, preco, variacao, media):
self.variacao = variacao
self.media = media

def __repr__(self):
return json.dumps(self, default=lambda o: o.__dict__)

@classmethod
def from_dict(cls, data):
return cls(data['atleta_id'], data['rodada_id'], data['pontos'], data['preco'], data['variacao'], data['media'])


class Time(object):
class Time(BaseModel):
""" Time """

def __init__(self, patrimonio, valor_time, ultima_pontuacao, atletas, info):
Expand All @@ -201,9 +182,6 @@ def __init__(self, patrimonio, valor_time, ultima_pontuacao, atletas, info):
self.atletas = atletas
self.info = info

def __repr__(self):
return json.dumps(self, default=lambda o: o.__dict__)

@classmethod
def from_dict(cls, data, clubes):
data['atletas'].sort(key=lambda a: a['posicao_id'])
Expand All @@ -212,7 +190,7 @@ def from_dict(cls, data, clubes):
return cls(data['patrimonio'], data['valor_time'], data['pontos'], atletas, info)


class TimeInfo(object):
class TimeInfo(BaseModel):
""" Time Info """

def __init__(self, time_id, nome, nome_cartola, slug, assinante, pontos):
Expand All @@ -223,9 +201,6 @@ def __init__(self, time_id, nome, nome_cartola, slug, assinante, pontos):
self.assinante = assinante
self.pontos = pontos

def __repr__(self):
return json.dumps(self, default=lambda o: o.__dict__)

@classmethod
def from_dict(cls, data, ranking=None):
pontos = data['pontos'][ranking] if ranking and ranking in data['pontos'] else None
Expand Down
10 changes: 9 additions & 1 deletion cartolafc/util.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# -*- coding: utf-8 -*-

import datetime
import json
import logging
import re
import unicodedata

from cartolafc.error import CartolaFCError, CartolaFCOverloadError
from .errors import CartolaFCError, CartolaFCOverloadError


def _strip_accents(text):
Expand All @@ -24,6 +25,13 @@ def convert_team_name_to_slug(name):
return slug[:-1] if slug.endswith('-') else slug


def json_default(value):
if isinstance(value, datetime.datetime):
return dict(year=value.year, month=value.month, day=value.day, hour=value.hour, minute=value.minute,
second=value.second, microsecond=value.microsecond, tzinfo=value.tzinfo)
return value.__dict__


def parse_and_check_cartolafc(json_data):
try:
data = json.loads(json_data)
Expand Down
20 changes: 0 additions & 20 deletions docs/Makefile

This file was deleted.

36 changes: 0 additions & 36 deletions docs/make.bat

This file was deleted.

Loading

0 comments on commit 728ae2c

Please sign in to comment.