Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""LICENSE
2Copyright 2020 Hermann Krumrey <hermann@krumreyh.com>
4This file is part of betbot.
6betbot is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
11betbot is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
16You should have received a copy of the GNU General Public License
17along with betbot. If not, see <http://www.gnu.org/licenses/>.
18LICENSE"""
20from selenium.webdriver import Firefox
21from selenium.webdriver.firefox.options import Options
22from typing import Dict, Tuple
25class OddsPortal:
26 """
27 Class that handles retrieving bet data using oddsportal.com
28 """
30 TEAM_MAP = {
31 "Nurnberg": "FCN",
32 "Mainz": "M05",
33 "Bayer Leverkusen": "B04",
34 "Dortmund": "BVB",
35 "B. Monchengladbach": "BMG",
36 "Eintracht Frankfurt": "SGE",
37 "Augsburg": "FCA",
38 "Bayern Munich": "FCB",
39 "Schalke": "S04",
40 "Dusseldorf": "F95",
41 "Hannover": "H96",
42 "Hertha Berlin": "BSC",
43 "RB Leipzig": "RBL",
44 "Freiburg": "SCF",
45 "Hoffenheim": "TSG",
46 "Stuttgart": "VFB",
47 "Wolfsburg": "WOB",
48 "Werder Bremen": "BRE",
49 "Union Berlin": "FCU",
50 "Paderborn": "SCP",
51 "FC Koln": "KOE",
52 "Arminia Bielefeld": "DSC",
53 "Greuther Furth": "SGF",
54 "Bochum": "BOC",
55 "Heidenheim": "HDH",
56 "Aue": "AUE",
57 "Hansa Rostock": "FCH",
58 "Ingolstadt": "FCI",
59 "St. Pauli": "STP",
60 "Hamburger SV": "HSV",
61 "Holstein Kiel": "KIE",
62 "Regensburg": "SSV",
63 "Karlsruher": "KSC",
64 "SG Dynamo Dresden": "SGD",
65 "Darmstadt": "D98",
66 "Sandhausen": "SVS",
67 "VfL Osnabruck": "OSN",
68 "Duisburg": "MSV",
69 "Hallescher": "HFC",
70 "Meppen": "SVM",
71 "Kaiserslautern": "FCK",
72 "Braunschweig": "BRA",
73 "Mannheim": "MAN",
74 "Magdeburg": "FCM",
75 "Munich 1860": "MÜN",
76 "Wurzburger Kickers": "WÜR",
77 "TSV Havelse": "HAV",
78 "Saarbrucken": "FCS",
79 "Zwickau": "ZWI",
80 "Dortmund II": "BV2",
81 "Viktoria Berlin": "VBE",
82 "Viktoria Koln": "VKO",
83 "Verl": "SCV",
84 "Turkgucu Munchen": "TÜR",
85 "Freiburg II": "SC2",
86 "Wehen": "WIE"
87 }
89 def __init__(self):
90 """
91 Initializes the oddsportal scraper
92 """
93 options = Options()
94 options.headless = True
95 self.driver = Firefox(options=options)
97 def get_odds(self, league: str) \
98 -> Dict[Tuple[str, str], Tuple[float, float, float]]:
99 """
100 Retrieves the odds for upcoming matches from oddsportal.com
101 :param league: The league to search for
102 :return: Odds for the matches (home, draw, odds)
103 """
104 matches: Dict[Tuple[str, str], Tuple[float, float, float]] = {}
105 base_url = "https://www.oddsportal.com/soccer/"
106 endpoint = {
107 "bl1": "germany/bundesliga/",
108 "bl2": "germany/2-bundesliga/",
109 "bl3": "germany/3-liga/"
110 }.get(league)
111 if endpoint is None:
112 return matches
114 self.driver.get(base_url + endpoint)
115 table = self.driver.find_element_by_id("tournamentTable")
116 for row in table.find_elements_by_tag_name("tr"):
117 participant_tag = \
118 row.find_elements_by_class_name("table-participant")
119 if len(participant_tag) == 0:
120 continue
122 try:
123 home_team, away_team = participant_tag[0].text.split(" - ")
124 except ValueError:
125 continue
127 home_abbrv = self.TEAM_MAP.get(home_team.strip())
128 away_abbrv = self.TEAM_MAP.get(away_team.strip())
129 if home_abbrv is None or away_abbrv is None:
130 continue
131 match_tuple = (home_abbrv, away_abbrv)
132 odds = row.find_elements_by_class_name("odds-nowrp")
133 try:
134 matches[match_tuple] = (
135 float(odds[0].text),
136 float(odds[1].text),
137 float(odds[2].text)
138 )
139 except ValueError:
140 continue
142 return matches