def post_results(self):
     print ("Posting results...")
     while True:
         try:
             PTFinter.enter_results(self.league, self.matches, self.driver)
             break
         except errors.UnexpectedAlertPresentException:
             self.driver.switch_to_alert().accept()
             league_name = self.league.get_league_name()
             print("Alert Error for {}".format(league_name))
             errors.log_error("Alert Error for {}".format(league_name))
 def update_bonus(self):
     """Gets bonus point values from www.predictthefootball.com"""
     # Error margin is base value multiplied by a modifier, calculated as
     # the time until the game divided by 12 hours (max of 1).
     time_remaining = self.time - dt.datetime.now()
     time_fraction = time_remaining / dt.timedelta(0.5)
     result_error_margin = min(0.5, 0.5 * time_fraction)
     score_error_margin = min(0.3, 0.3 * time_fraction)
     self.no_bonus_results, self.no_bonus_scores = \
         PTFinter.get_no_bonus(self.league, self.ptfID,
             result_error_margin, score_error_margin, self.prediction)
    def get_upcoming(self, within_days=2):
        try:
            ptf_matches_info = PTFinter.upcoming_games(self.driver, self.league)
        except errors.UnexpectedAlertPresentException:
            self.driver.switch_to_alert().accept()
            league_name = self.league.get_league_name()
            print("Alert Error for {}".format(league_name))
            errors.log_error("Alert Error for {}".format(league_name))
            ptf_matches_info = PTFinter.upcoming_games(self.driver, self.league)

        league_teams = self.league.get_teams()

        matches = []
        time_now = dt.datetime.now()
        for info in ptf_matches_info:
            # Window of time to make predictions
            # Default is between 2 days before match to 2 minutes before
            predict_within = [
                info[3] - dt.timedelta(days=within_days),
                info[3] - dt.timedelta(minutes=2)]
            if not predict_within[0] < time_now < predict_within[1]:
                continue
            # set home and away to the home and away teams
            home = None
            away = None
            for team in league_teams:
                if team.get_identifier("PTF") == info[0]:
                    home = team
                elif team.get_identifier("PTF") == info[1]:
                    away = team
            if home is None:
                raise ValueError("{} not found in teams".format(info[0]))
            elif away is None:
                raise ValueError("{} not found in teams".format(info[1]))

            # Create a Match object and add it to the list of matches
            newmatch = match.Match(
                self.league, home, away, info[2], info[3], info[4])
            matches.append(newmatch)
        self.matches = matches
 def clear_footprint(self):
     """Make sure that the matches have at least a temporary prediction."""
     PTFinter.enter_results(
         self.league, self.matches, self.driver, dummy=True)
import errors
import time


if __name__ == "__main__":
    errors.log_start()
    try:
        from config import email, password
        #valid_import = PTFinter.test_login(email, password)
        valid_import = True
    except ImportError:
        valid_import = False

    if not valid_import:
        email, password = login.get_login_details()
        if PTFinter.test_login(email, password):
            login.save_config(email, password)
        else:
            print ("Incorrect email or password. Exiting...")
            quit()

    print ("Login details confirmed, starting script...")

    driver = webdriver.Chrome()

    login_url = "https://www.predictthefootball.com/site/login"
    driver.get(login_url)
    driver.find_element_by_name("LoginForm[email]").send_keys(email)
    driver.find_element_by_name("LoginForm[password]").send_keys(password)
    driver.find_element_by_name("yt0").click()