示例#1
0
def update_games():
    """
    downloads html, parses info from html, saves results, saves done games urls and ids to list
    :return:
    """

    # get country name, competition name
    country_name, competition_name = update_seasons()
    seasons = scraper.get_starting_values('data/seasons.json')
    season_names = sorted(list(seasons[country_name][competition_name].keys()))

    # select season and get it's urls
    selection = print_options(season_names)
    season = season_names[selection]
    season_url = seasons[country_name][competition_name][season]['url']

    # find game urls for this season
    game_urls_list = scraper.get_game_urls(season_url)

    game_count = 0

    # iterate over game urls
    for url in game_urls_list:

        game_id = url.split('/')[-2]

        # if game not saved, get game info save it and the fact that it's saved to seasons list
        if game_id not in seasons[country_name][competition_name][season][
                'game_ids']:

            scraper.get_games(url)

            seasons[country_name][competition_name][season][
                'game_urls'].append(url)
            seasons[country_name][competition_name][season]['game_ids'].append(
                game_id)

            with open('data/seasons.json', 'w') as fp:
                json.dump(seasons, fp, ensure_ascii=False)

            game_count += 1

            # sleep before next html download
            time.sleep(random.randint(sleep_min, sleep_max))

    print(country_name, competition_name, season, game_count, 'games added')
示例#2
0
    def get(self, genre):
        params = {"genre": genre}

        games = get_games(params)

        if games:
            return games, 200
        else:
            return {'message': 'Cannot find games'}, 404
示例#3
0
    def get(self, tag_id):
        params = {"tags": tag_id}

        games = get_games(params)

        if games:
            return games, 200
        else:
            return {'message': 'Cannot find games'}, 404
示例#4
0
    def get(self):

        params = {"specials": '1'}

        games = get_games(params)

        if games:
            return games, 200
        else:
            return {'message': 'Cannot find games'}, 404
from typing import ChainMap
from file_manger import get_template, write_file, read_cache, write_cache, check_directories
from scraper import get_games
from scorigami_table import ScorigamiTable

CACHE_FILE = 'data/scorgiami_cache.json'


def generate_index(score_table):
    max_score = score_table.max_score()
    template = get_template('index.html')
    write_file(template.render(table=score_table, max_score=max_score),
               'index.html')


if __name__ == "__main__":
    check_directories()
    cached_games, cached_years = read_cache(CACHE_FILE)
    new_games, all_years = get_games(cached_years)

    all_games = cached_games
    for year, games in new_games.items():
        all_games.extend(games)

    table = ScorigamiTable(all_games)
    generate_index(table)

    important_games = table.extract_games()
    write_cache(CACHE_FILE, important_games, all_years)