Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
def match_page_url(path, url):
    season = odds_tools.read_json_file(path)
    if not season:
        return ''
    for match_url in season['match_sources']:
        if not season['match_sources'][match_url]:
            return match_url
    return ''
Ejemplo n.º 3
0
Archivo: odds.py Proyecto: krylov/sport
def match_page_url(path, url):
    season = odds_tools.read_json_file(path)
    if not season:
        return ""
    for match_url in season["match_sources"]:
        if not season["match_sources"][match_url]:
            return match_url
    return ""
Ejemplo n.º 4
0
def season_page_url(path, url):
    season = odds_tools.read_json_file(path)
    if not (season and season['pages']):
        return url
    ix = 1
    for loaded in season['pages']:
        if not loaded:
            return season['source'] + '#/page/' + str(ix) + '/'
        ix += 1
    return ''
Ejemplo n.º 5
0
Archivo: odds.py Proyecto: krylov/sport
def season_page_url(path, url):
    season = odds_tools.read_json_file(path)
    if not (season and season["pages"]):
        return url
    ix = 1
    for loaded in season["pages"]:
        if not loaded:
            return season["source"] + "#/page/" + str(ix) + "/"
        ix += 1
    return ""
Ejemplo n.º 6
0
Archivo: odds.py Proyecto: krylov/sport
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()
Ejemplo n.º 7
0
def modify_if_current_season(path):
    file_part = os.path.basename(path)
    file_name = os.path.splitext(file_part)[0]
    m = re.findall('\-\d{4}', file_name)
    if m:  # if m isn't empty season isn't current
        return
    season = odds_tools.read_json_file(path)
    if not season:
        return
    season['pages'] = []
    fw = open(path, 'w')
    fw.write(json.dumps(season, False, False))
Ejemplo n.º 8
0
Archivo: odds.py Proyecto: krylov/sport
def modify_if_current_season(path):
    file_part = os.path.basename(path)
    file_name = os.path.splitext(file_part)[0]
    m = re.findall("\-\d{4}", file_name)
    if m:  # if m isn't empty season isn't current
        return
    season = odds_tools.read_json_file(path)
    if not season:
        return
    season["pages"] = []
    fw = open(path, "w")
    fw.write(json.dumps(season, False, False))
Ejemplo n.º 9
0
Archivo: odds.py Proyecto: krylov/sport
def mark_match(path, url):
    season = odds_tools.read_json_file(path)
    if not season:
        return false
    if url in season["match_sources"]:
        season["match_sources"][url] = True
        fw = open(path, "w")
        fw.write(json.dumps(season, False, False))
        n_loaded = 0
        for url in season["match_sources"]:
            if season["match_sources"][url]:
                n_loaded += 1
        print "Uploaded " + str(n_loaded) + " of " + str(len(season["match_sources"])) + "."
        return True
    return False
Ejemplo n.º 10
0
def mark_match(path, url):
    season = odds_tools.read_json_file(path)
    if not season:
        return false
    if url in season['match_sources']:
        season['match_sources'][url] = True
        fw = open(path, 'w')
        fw.write(json.dumps(season, False, False))
        n_loaded = 0
        for url in season['match_sources']:
            if season['match_sources'][url]:
                n_loaded += 1
        print 'Uploaded ' + str(n_loaded) + ' of ' + str(
            len(season['match_sources'])) + '.'
        return True
    return False
Ejemplo n.º 11
0
Archivo: odds.py Proyecto: krylov/sport
def match_odds_url(path, url):
    match = odds_tools.read_json_file(path)
    if not match:
        return url
    while 1:
        keys = match["odds"].keys()
        pc = part_code()
        for k in keys:
            if match["odds"][k]:
                parts = match["odds"][k].keys()
                for p in parts:
                    current_url = url + "#" + k + ";" + pc[p.lower()]
                    if not (match["odds"][k][p] or is_url_ignored(current_url)):
                        if ignore_url(current_url):
                            continue
                        return current_url
            else:
                return url + "#" + k
        return ""
Ejemplo n.º 12
0
def match_odds_url(path, url):
    match = odds_tools.read_json_file(path)
    if not match:
        return url
    while 1:
        keys = match['odds'].keys()
        pc = part_code()
        for k in keys:
            if match['odds'][k]:
                parts = match['odds'][k].keys()
                for p in parts:
                    current_url = url + '#' + k + ';' + pc[p.lower()]
                    if not (match['odds'][k][p]
                            or is_url_ignored(current_url)):
                        if ignore_url(current_url):
                            continue
                        return current_url
            else:
                return url + '#' + k
        return ''