def correct_season_name(season_url, years): print 'SEASON URL: %s' % (season_url, ) print 'YEARS: %s' % (years, ) json_path = odds_tools.path_from_season_url(season_url) new_json_path = json_path.replace('.json', '-%s.json' % (years, )) shutil.copyfile(json_path, new_json_path) print 'JSON PATH: %s' % (json_path, ) print 'NEW JSON PATH: %s' % (new_json_path, ) season = odds_tools.read_json_file(new_json_path) tour = odds_tools.tour_from_season_url(season['source']) print 'TOUR: %s' % (tour, ) new_tour = '%s-%s' % ( tour, years, ) season['source'] = season['source'].replace(tour, new_tour) print 'NEW SOURCE: %s' % (season['source']) match_sources = season['match_sources'] new_match_sources = {} for src in match_sources: new_src = src.replace(tour, new_tour) new_match_sources[new_src] = match_sources[src] season['match_sources'] = new_match_sources fw = open(new_json_path, 'w') fw.write(json.dumps(season, False, False)) fw.close() country_folder = os.path.dirname(new_json_path) tour_folder = '%s/%s' % ( country_folder, tour, ) new_tour_folder = '%s/%s' % ( country_folder, new_tour, ) print 'NEW TOUR FOLDER: %s' % (new_tour_folder, ) if not os.path.isdir(new_tour_folder): os.mkdir(new_tour_folder) shutil.copyfile(json_path, new_json_path) json_files = [f for f in os.listdir(tour_folder)] for f in json_files: new_match_path = '%s/%s' % ( new_tour_folder, f, ) if not os.path.isfile(new_match_path): match_path = '%s/%s' % (tour_folder, f) if not os.path.isdir(match_path): print 'MATCH_PATH: %s' % match_path shutil.copyfile(match_path, new_match_path) match = odds_tools.read_json_file(new_match_path) match['source'] = match['source'].replace(tour, new_tour) fw = open(new_match_path, 'w') fw.write(json.dumps(match, False, False)) fw.close()
def load_all_match_urls(season_url): json_path = odds_tools.path_from_season_url(season_url) modify_if_current_season(json_path) while 1: print '------------------------------------------' print 'Current Time: ' + str(datetime.now()) url = season_page_url(json_path, season_url) if not url: break load_match_urls(url) print '------------------------------------------' while 1: match_url = match_page_url(json_path, season_url) if not match_url: break load_all_odds(match_url) mark_match(json_path, match_url)
def load_all_match_urls(season_url): json_path = odds_tools.path_from_season_url(season_url) modify_if_current_season(json_path) while 1: print "------------------------------------------" print "Current Time: " + str(datetime.now()) url = season_page_url(json_path, season_url) if not url: break load_match_urls(url) print "------------------------------------------" while 1: match_url = match_page_url(json_path, season_url) if not match_url: break load_all_odds(match_url) mark_match(json_path, match_url)
def correct_season_name(season_url, years): print "SEASON URL: %s" % (season_url,) print "YEARS: %s" % (years,) json_path = odds_tools.path_from_season_url(season_url) new_json_path = json_path.replace(".json", "-%s.json" % (years,)) shutil.copyfile(json_path, new_json_path) print "JSON PATH: %s" % (json_path,) print "NEW JSON PATH: %s" % (new_json_path,) season = odds_tools.read_json_file(new_json_path) tour = odds_tools.tour_from_season_url(season["source"]) print "TOUR: %s" % (tour,) new_tour = "%s-%s" % (tour, years) season["source"] = season["source"].replace(tour, new_tour) print "NEW SOURCE: %s" % (season["source"]) match_sources = season["match_sources"] new_match_sources = {} for src in match_sources: new_src = src.replace(tour, new_tour) new_match_sources[new_src] = match_sources[src] season["match_sources"] = new_match_sources fw = open(new_json_path, "w") fw.write(json.dumps(season, False, False)) fw.close() country_folder = os.path.dirname(new_json_path) tour_folder = "%s/%s" % (country_folder, tour) new_tour_folder = "%s/%s" % (country_folder, new_tour) print "NEW TOUR FOLDER: %s" % (new_tour_folder,) if not os.path.isdir(new_tour_folder): os.mkdir(new_tour_folder) shutil.copyfile(json_path, new_json_path) json_files = [f for f in os.listdir(tour_folder)] for f in json_files: new_match_path = "%s/%s" % (new_tour_folder, f) if not os.path.isfile(new_match_path): match_path = "%s/%s" % (tour_folder, f) if not os.path.isdir(match_path): print "MATCH_PATH: %s" % match_path shutil.copyfile(match_path, new_match_path) match = odds_tools.read_json_file(new_match_path) match["source"] = match["source"].replace(tour, new_tour) fw = open(new_match_path, "w") fw.write(json.dumps(match, False, False)) fw.close()