Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: update response parse method of message_url for empty nations o… #447

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 55 additions & 49 deletions fut/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import random
import re
import time
import base64

import pyotp
import requests
Expand Down Expand Up @@ -184,85 +185,91 @@ def itemParse(item_data, full=True):
# return requests.get(url, timeout=timeout).json()


def __get_message_url_res_json(timeout=timeout):
rc = requests.get(messages_url, timeout=timeout)
rc.encoding = 'utf-8'
return {
base64.b64decode(
k).decode('utf-8'): base64.b64decode(
v).decode('utf-8') for k, v in rc.json().items()}


# TODO: optimize messages (parse whole messages once!), xml parser might be faster
# TODO: parse more data (short club names etc.)
def nations(timeout=timeout):
"""Return all nations in dict {id0: nation0, id1: nation1}.

:params year: Year.
"""
rc = requests.get(messages_url, timeout=timeout)
rc.encoding = 'utf-8' # guessing takes huge amount of cpu time
rc = rc.text
data = re.findall('"search.nationName.nation([0-9]+)": "(.+)"', rc)
nations = {}
for i in data:
nations[int(i[0])] = i[1]
return nations
return {
int(
re.sub(
'search.nationName.nation', '', k
)): v for k, v in __get_message_url_res_json().items(
) if re.match(
"search.nationName.nation([0-9]+)", k)}


def leagues(year=2019, timeout=timeout):
"""Return all leagues in dict {id0: league0, id1: legaue1}.

:params year: Year.
"""
rc = requests.get(messages_url, timeout=timeout)
rc.encoding = 'utf-8' # guessing takes huge amount of cpu time
rc = rc.text
data = re.findall('"global.leagueFull.%s.league([0-9]+)": "(.+)"' % year, rc)
leagues = {}
for i in data:
leagues[int(i[0])] = i[1]
return leagues
return {
int(
re.sub(
"global.leagueFull.%s.league" % year, '', k
)): v for k, v in __get_message_url_res_json().items(
) if re.match(
"global.leagueFull.%s.league([0-9]+)" % year, k)}


def teams(year=2019, timeout=timeout):
"""Return all teams in dict {id0: team0, id1: team1}.

:params year: Year.
"""
rc = requests.get(messages_url, timeout=timeout)
rc.encoding = 'utf-8' # guessing takes huge amount of cpu time
rc = rc.text
data = re.findall('"global.teamFull.%s.team([0-9]+)": "(.+)"' % year, rc)
teams = {}
for i in data:
teams[int(i[0])] = i[1]
return teams
return {
int(
re.sub(
'global.teamabbr15.%s.team' % year, '', k
)): v for k, v in __get_message_url_res_json().items(
) if re.match(
'global.teamabbr15.%s.team([0-9]+)' % year, k)}


def stadiums(year=2019, timeout=timeout):
"""Return all stadium in dict {id0: stadium0, id1: stadium1}.

:params year: Year.
"""
rc = requests.get(messages_url, timeout=timeout)
rc.encoding = 'utf-8' # guessing takes huge amount of cpu time
rc = rc.text
data = re.findall('"global.stadiumFull.%s.stadium([0-9]+)": "(.+)"' % year, rc)
stadiums = {}
for i in data:
stadiums[int(i[0])] = i[1]
return stadiums
return {
int(
re.sub(
'global.stadiumFull.%s.stadium' % year, '', k
)): v for k, v in __get_message_url_res_json().items(
) if re.match(
'global.stadiumFull.%s.stadium([0-9]+)' % year, k)}


def balls(timeout=timeout):
"""Return all balls in dict {id0: ball0, id1: ball1}."""
rc = requests.get(messages_url, timeout=timeout)
rc.encoding = 'utf-8' # guessing takes huge amount of cpu time
rc = rc.text
data = re.findall('"BallName_([0-9]+)": "(.+)"', rc)
balls = {}
for i in data:
balls[int(i[0])] = i[1]
return balls

return {
int(
re.sub(
'BallName_', '', k
)): v for k, v in __get_message_url_res_json().items(
) if re.match(
'BallName_([0-9]+)', k)}


def players(timeout=timeout):
"""Return all players in dict {id: c, f, l, n, r}.
id, rank, nationality(?), first name, last name.
"""
rc = requests.get('{0}{1}.json'.format(card_info_url, 'players'), timeout=timeout).json()
rc = requests.get(
'{0}{1}.json'.format(card_info_url, 'players'), timeout=timeout).json()
players = {}
for i in rc['Players'] + rc['LegendsPlayers']:
players[i['id']] = {'id': i['id'],
Expand All @@ -278,14 +285,13 @@ def playstyles(year=2019, timeout=timeout):

:params year: Year.
"""
rc = requests.get(messages_url, timeout=timeout)
rc.encoding = 'utf-8' # guessing takes huge amount of cpu time
rc = rc.text
data = re.findall('"playstyles.%s.playstyle([0-9]+)": "(.+)"' % year, rc)
playstyles = {}
for i in data:
playstyles[int(i[0])] = i[1]
return playstyles
return {
int(
re.sub(
'playstyles.%s.playstyle' % year, '', k
)): v for k, v in __get_message_url_res_json().items(
) if re.match(
'playstyles.%s.playstyle([0-9]+)' % year, k)}


class Core(object):
Expand Down