Hide keyboard shortcuts

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#!/usr/bin/env python3 

2"""LICENSE 

3Copyright 2017 Hermann Krumrey <hermann@krumreyh.com> 

4 

5This file is part of bundesliga-tippspiel. 

6 

7bundesliga-tippspiel is free software: you can redistribute it and/or modify 

8it under the terms of the GNU General Public License as published by 

9the Free Software Foundation, either version 3 of the License, or 

10(at your option) any later version. 

11 

12bundesliga-tippspiel is distributed in the hope that it will be useful, 

13but WITHOUT ANY WARRANTY; without even the implied warranty of 

14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

15GNU General Public License for more details. 

16 

17You should have received a copy of the GNU General Public License 

18along with bundesliga-tippspiel. If not, see <http://www.gnu.org/licenses/>. 

19LICENSE""" 

20 

21import time 

22import logging 

23from typing import List, Tuple 

24from betbot.api.ApiConnection import ApiConnection 

25from betbot.prediction import predictors 

26 

27 

28def main( 

29 predictor_name: str, 

30 username: str, 

31 password: str, 

32 url: str, 

33 loop: bool = False 

34): 

35 """ 

36 The main function of the betbot 

37 Predicts results and places bets accordingly 

38 :param predictor_name: The name of the predictor to use 

39 :param username: The username for bundesliga-tippspiel 

40 :param password: The password for bundesliga-tippspiel 

41 :param url: The base URL for the bundesliga-tippspiel instance 

42 :param loop: If true will place new bets once an hour 

43 :return: None 

44 """ 

45 logging.info(f"Starting betbot for predictor {predictor_name} " 

46 f"and user {username}@{url}") 

47 

48 api = ApiConnection(username, password, url) 

49 

50 if not api.authorized(): 

51 return 

52 

53 predictor_map = { 

54 x.name(): x for x in predictors 

55 } 

56 predictor_cls = predictor_map[predictor_name] 

57 

58 while True: 

59 leagues = api.get_active_leagues() 

60 for league, season in leagues: 

61 logging.info(f"Placing bets for league {league}/{season}") 

62 predictor = predictor_cls(api, league, season) 

63 matches = api.get_current_matchday_matches(league, season) 

64 bets = predictor.predict(matches) 

65 api.place_bets(bets) 

66 

67 if loop: 

68 time.sleep(60 * 60) 

69 else: 

70 break 

71 

72 api.logout() 

73 

74 

75def multi_main( 

76 url: str, 

77 config: List[Tuple[str, str, str]], 

78 loop: bool = False 

79): 

80 """ 

81 Predicts using multiple procedures simultaneously 

82 :param url: The base URL for the bundesliga-tippspiel site 

83 :param config: The predictor names and credentials for the API 

84 :param loop: Whether or not to loop this once an hour 

85 :return: None 

86 """ 

87 while True: 

88 for predictor_name, user, password in config: 

89 main(predictor_name, user, password, url, False) 

90 if loop: 

91 time.sleep(60 * 60) 

92 else: 

93 break