Skip to content

Commit

Permalink
Mais modular
Browse files Browse the repository at this point in the history
  • Loading branch information
ballomud committed Jun 15, 2015
1 parent 45719d9 commit 0a9b18e
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions Scrapers/Scouts.py
Expand Up @@ -29,9 +29,7 @@
import mechanize
import cookielib


def ScrapeScouts(LOGIN_EMAIL, LOGIN_SENHA, USER_AGENT):

def DownloadScouts(LOGIN_EMAIL, LOGIN_SENHA, USER_AGENT):
# Consts
SCOUTS_URL = 'http://cartolafc.globo.com/mercado/filtrar.json?page='
LOGIN_URL = 'https://loginfree.globo.com/login/438'
Expand Down Expand Up @@ -71,9 +69,9 @@ def ScrapeScouts(LOGIN_EMAIL, LOGIN_SENHA, USER_AGENT):
for i in it.count(1):
url = SCOUTS_URL + str(i)

r = br.open(url)
j = json.loads(r.read())
jsonRaw.append(j)
r = br.open(url).read()
j = json.loads(r)
jsonRaw.append(r)

pgAtual = int(j['page']['atual'])
pgTotal = int(j['page']['total'])
Expand All @@ -85,10 +83,13 @@ def ScrapeScouts(LOGIN_EMAIL, LOGIN_SENHA, USER_AGENT):

print '[LOG] Downloading Scouts Terminado'

# Minera Rodada
return jsonRaw


def ProcessScouts(jsonRaw):
print '[LOG] Processamento de Scouts Iniciado'

# Minera Rodada
rodada = jsonRaw[0]['rodada_id'] - 1

# Concatena lista de atletas dos arquivos
Expand Down Expand Up @@ -122,6 +123,18 @@ def ScrapeScouts(LOGIN_EMAIL, LOGIN_SENHA, USER_AGENT):

print '[LOG] Processamento de Scouts Terminado'

return ScoutsDict


def ScrapeScouts(LOGIN_EMAIL, LOGIN_SENHA, USER_AGENT):

# Download dados
jsonRaw = DownloadScouts(LOGIN_EMAIL, LOGIN_SENHA, USER_AGENT)

# Processa dados
jsonRaw = [json.loads(j) for j in jsonRaw]
ScoutsDict = ProcessScouts(jsonRaw)

# Save DataFrame to SQLite

print '[LOG] Transferindo Scouts para SQLite'
Expand Down

0 comments on commit 0a9b18e

Please sign in to comment.