def extract(self): global api start_time = current_time() api=api.replace("eventStartFrom=YYYY-MM-DDTHH:MM:SS","eventStartFrom="+str(arrow.utcnow().replace(hours=-hours_back))[0:19]) api=api.replace("eventStartTo=YYYY-MM-DDTHH:MM:SS", "eventStartTo="+str(arrow.utcnow().replace(hours=+hours_forward))[0:19]) response = requests.get(api) json = response.json() print("time to get: " + str(current_time()-start_time)) games = json.get(ROOT) for game in games: id = game.get(ID) time = format_time(BETSSON,game.get(TIME).replace("T"," ").replace("Z","")) region = game.get(REGION) league = game.get(LEAGUE) home = game.get(TEAMS)[HOME].get(TEAM) away = game.get(TEAMS)[AWAY].get(TEAM) print(home + " " + away) bets = game.get(BET_TYPES)[MATCH_WINNER].get(MATCH_WINNER_BETS) home_bet = bets[HOME_BET].get(BET) draw_bet = bets[DRAW_BET].get(BET) away_bet = bets[AWAY_BET].get(BET) match_id_query = process_query(home,away) match_id = get_match_id(driver,match_id_query,time,None).decode('utf-8') #print(match_id) print(str(id) + " " + time + " " + league + " " + home + " " + away + " " + str(home_bet) + " " + str(draw_bet) + " " + str(away_bet) + " " + match_id)
def golden_ratio(f_sym_t): a = random.randint(0, 13) - 1000 # random start of interval b = random.randint(0, 13) + 900 # random end of interval while (True): interval_length = abs(b - a) x_alpha = a + functions.ALPHA * interval_length x_betta = a + functions.BETTA * interval_length f_a = f_sym_t.subs({sym_t: a}) f_b = f_sym_t.subs({sym_t: b}) f_x_alpha = f_sym_t.subs({sym_t: x_alpha}) f_x_betta = f_sym_t.subs({sym_t: x_betta}) # make sure interval is OK: if (((f_a > f_x_alpha) | (f_a > f_x_betta)) & ((f_b > f_x_betta) | (f_b > f_x_alpha))): break else: a -= 1000 b += 1000 time_start = functions.current_time( ) # program started at <time_start> time iteration_number = 1 while (True): interval_length = abs(b - a) x_alpha = a + functions.ALPHA * interval_length x_betta = a + functions.BETTA * interval_length f_x_alpha = f_sym_t.subs({sym_t: x_alpha}) f_x_betta = f_sym_t.subs({sym_t: x_betta}) if (f_x_alpha < f_x_betta): a = x_betta else: b = x_alpha interval_length = abs(b - a) time_calculation = functions.time_dif(time_start) if (interval_length < functions.PRECISION): # compare with precision break if (time_calculation > functions.TIME_LIMIT): # nobody wants to wait too much print("WARNING: long time calculation. interval_length: %.4f" % interval_length) break iteration_number += 1 return ((a + b) / 2)
def dichotomy(f_sym_t, delta=0): a = random.randint(0, 13) - 1000 # random start of interval b = random.randint(0, 13) + 900 # random end of interval if (delta == 0): delta = random.uniform(0, functions.PRECISION / 2) while (True): x_l1 = (a + b) / 2 - delta x_l2 = (a + b) / 2 + delta f_a = f_sym_t.subs({sym_t: a}) f_b = f_sym_t.subs({sym_t: b}) f_x_1 = f_sym_t.subs({sym_t: x_l1}) f_x_2 = f_sym_t.subs({sym_t: x_l2}) # make sure interval is OK: if (((f_a > f_x_1) | (f_a > f_x_2)) & ((f_b > f_x_2) | (f_b > f_x_1))): break else: a -= 1000 b += 1000 time_start = functions.current_time( ) # program started at <time_start> time iteration_number = 1 while (True): x_l1 = (a + b) / 2 - delta x_l2 = (a + b) / 2 + delta f_x_1 = f_sym_t.subs({sym_t: x_l1}) f_x_2 = f_sym_t.subs({sym_t: x_l2}) if (f_x_1 < f_x_2): b = x_l2 else: a = x_l1 interval_length = abs(b - a) time_calculation = functions.time_dif(time_start) if (interval_length < functions.PRECISION): # compare with precision break if (time_calculation > functions.TIME_LIMIT): # nobody wants to wait too much print("WARNING: long time calculation. interval_length: %.4f" % interval_length) break iteration_number += 1 return ((a + b) / 2)
else: find_t = golden_ratio print(" X[0]") for key in x.keys(): print("x[%s] = % .3f" % (key, x[key])) grad_x = dict() # gradient contains derivatives for key in x.keys(): grad_x[key] = sympy.diff(f_syms, key, 1) # derivative of f_syms by key, order 1 # ************************* find grad END ************************* # ************************* iteration BEGIN ************************* stop_iteration = False # condition to stop: grad_x[i] < PRECISION time_start = functions.current_time() # program started at <time_start> time iteration_number = 0 for key in grad_x.keys(): if (abs(grad_x[key].subs({key: x[key]})) < functions.PRECISION): # grad_x < PRECISION? stop_iteration = True break while ((not stop_iteration) & (iteration_number < functions.ITERATION_LIMIT)): iteration_number += 1 x_sym_t = dict() # each component contains symbol <t> for key in x.keys(): x_sym_t[key] = x[key] - sym_t * grad_x[key].subs( {key: x[key]}) # iteration itself
def main(): """ Main function """ # Логирование message_level = logging.CRITICAL # Уровень логирования по умолчанию if grab_upwork_cfg.logging_level == 'DEBUG': message_level = logging.DEBUG elif grab_upwork_cfg.logging_level == 'INFO': message_level = logging.INFO elif grab_upwork_cfg.logging_level == 'WARNING': message_level = logging.WARNING elif grab_upwork_cfg.logging_level == 'ERROR': message_level = logging.ERROR log_flag = True if grab_upwork_cfg.logging_in_file.upper( ) and grab_upwork_cfg.logging_in_console.upper() == 'FALSE': log_flag = False print 'Logging is OFF.' logger = logging.getLogger() logger.setLevel(message_level) formatter = logging.Formatter('%(asctime)s %(levelname)s: %(message)s', datefmt='%Y-%m-%d_%H-%M-%S') # логирование в файл if grab_upwork_cfg.logging_in_file.upper() == 'TRUE': log_path = 'logs' if not path.exists(log_path): print 'ERROR: Path "' + log_path + '" not found.' exit(1) date_time_log_file = functions.current_time().replace(' ', '_').replace( ':', '-') log_file_name = date_time_log_file + '.log' file_handler = logging.FileHandler(log_path + path.sep + log_file_name) file_handler.setLevel(message_level) file_handler.setFormatter(formatter) logger.addHandler(file_handler) # логирование в консоль if grab_upwork_cfg.logging_in_console.upper() == 'TRUE': stream_handler = logging.StreamHandler() stream_handler.setLevel(message_level) stream_handler.setFormatter(formatter) logger.addHandler(stream_handler) if log_flag: logger.info('Logging level is ' + grab_upwork_cfg.logging_level) functions.clear_console() # Очистить консоль if log_flag: logger.info('Start at ' + functions.current_time()) # Поиск заказа по фразе if len(argv) != 2: if log_flag: logger.error('One parameter is required - the search string.') input() exit(1) else: order_find(argv[1], log_flag) # functions.console_input(logger, log_flag) # Получить ВЕБ-драйвер driver = functions.get_webdriver(grab_upwork_cfg, logger, log_flag) # Открыть главную страницу сайта full_server_name = 'http://' + grab_upwork_cfg.site_name driver.get(full_server_name) # Пока не найдём элемент или N секунд (N сек - для всех, до отмены, глобально) driver.implicitly_wait(grab_upwork_cfg.implicitly_wait_timeout) # Доступен ли сервер result = functions.site_available(driver, 'Upwork') if not result: if log_flag: logger.info('Website ' + grab_upwork_cfg.site_name + ' or page is unavailable.') driver.close() if log_flag: logger.info('Quit at ' + functions.current_time()) exit(1) # Логинимся if log_flag: logger.info('Login...') if upwork_logging(driver): if log_flag: logger.info('Successful login.') else: if log_flag: logger.error('Unsuccessful login.') driver.close() if log_flag: logger.info('Quit at ' + functions.current_time()) exit(1) # Поиск заказа по фразе # order_find() functions.console_input(logger, log_flag) # Разлогиниться if log_flag: logger.info('Logout...') if upwork_logout(driver, logger): if log_flag: logger.info('Successful logout.') else: if log_flag: logger.error('Unsuccessful logout') driver.close() if log_flag: logger.error('Quit at ' + functions.current_time()) exit(1) # functions.console_input(logger, log_flag) driver.close() # Закрыть браузер if log_flag: logger.info('Quit at ' + functions.current_time())