Code optimizsations
This commit is contained in:
+26
-34
@@ -2,28 +2,30 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2015-2016 by Martin Bley (martin@mb-oss.de)
|
||||
#
|
||||
#
|
||||
# This file is part of TipPy.
|
||||
#
|
||||
#
|
||||
# TipPy is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
#
|
||||
# TipPy is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with TipPy. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#
|
||||
import locale
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
|
||||
from suds.client import Client
|
||||
from zeep import Client
|
||||
from zeep.transports import Transport
|
||||
from requests import Session
|
||||
|
||||
|
||||
class OpenLiga(object):
|
||||
@@ -40,54 +42,44 @@ class OpenLiga(object):
|
||||
|
||||
self.debug = debug
|
||||
|
||||
# get a SUDS client object
|
||||
if self.proxyurl is None:
|
||||
try:
|
||||
self.client = Client(
|
||||
'http://www.openligadb.de/'
|
||||
+ 'Webservices/Sportsdata.asmx?WSDL')
|
||||
except (urllib.error.URLError):
|
||||
self.error += "Connect to webservice failed."
|
||||
else:
|
||||
try:
|
||||
t = suds.transport.http.HttpTransport()
|
||||
proxy = urllib.request.ProxyHandler({'http': proxyurl})
|
||||
opener = urllib.request.build_opener(proxy)
|
||||
t.urlopener = opener
|
||||
self.client = suds.client.Client(
|
||||
'http://www.openligadb.de/Webservices/'
|
||||
+ 'Sportsdata.asmx?WSDL', transport=t)
|
||||
except urllib.error.URLError as e:
|
||||
self.error += "Connect to webservice failed " \
|
||||
+ "(via proxy " + proxyurl + "): " + str(e) + "\n"
|
||||
# get a SOAP client object
|
||||
wsdl_url = 'http://www.openligadb.de/Webservices/Sportsdata.asmx?WSDL'
|
||||
|
||||
try:
|
||||
if proxyurl is None:
|
||||
self.client = Client(wsdl=wsdl_url)
|
||||
else:
|
||||
session = Session()
|
||||
session.proxies = {'http': proxyurl, 'https': proxyurl}
|
||||
transport = Transport(session=session)
|
||||
self.client = Client(wsdl=wsdl_url, transport=transport)
|
||||
except (urllib.error.URLError, Exception) as e:
|
||||
self.error += f"Connect to webservice failed: {str(e)}\n"
|
||||
|
||||
def getSeason(self, season, league='bl1'):
|
||||
""" Get the whole season.
|
||||
|
||||
Args: season and league shortcut (optional)
|
||||
"""
|
||||
return (self.client.service.GetMatchdataByLeagueSaison(
|
||||
return self.client.service.GetMatchdataByLeagueSaison(
|
||||
leagueShortcut=league, leagueSaison=season)
|
||||
)
|
||||
|
||||
def getMatchday(self, season, matchdaynumber, league='bl1'):
|
||||
""" Get matchday.
|
||||
|
||||
Args: season, matchdaynumber and league shortcut (optional)
|
||||
"""
|
||||
return (self.client.service.GetMatchdataByGroupLeagueSaison(
|
||||
return self.client.service.GetMatchdataByGroupLeagueSaison(
|
||||
groupOrderID=matchdaynumber,
|
||||
leagueShortcut=league,
|
||||
leagueSaison=season)
|
||||
)
|
||||
|
||||
def getTeams(self, season, league='bl1'):
|
||||
return (self.client.service.GetTeamsByLeagueSaison(
|
||||
return self.client.service.GetTeamsByLeagueSaison(
|
||||
leagueShortcut=league,
|
||||
leagueSaison=season)
|
||||
)
|
||||
|
||||
def getCurrentGroup(self, league):
|
||||
return (self.client.service.GetCurrentGroup(
|
||||
return self.client.service.GetCurrentGroup(
|
||||
leagueShortcut=league)
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user