Exemplo n.º 1
0
def main():
    args = parse_args()

    try:
        if not args.region:
            print(
                'No region selected. Please, use -r or --region and select a region to work on from the following '
                'list: {}'.format(REGIONS.keys()))
            return
        elif args.region.upper() not in REGIONS.keys():
            print('Region {} not supported. Try one of these: {}'.format(
                args.region.upper(), REGIONS.keys()))
            return
    except AttributeError:
        print(
            'Please, use -r or --region and select a region to work on from the following list: {}'
            .format(REGIONS.keys()))
        return

    if not args.league:
        print(
            'No league selected. Please, use -l or --league and select a league to work on from the following list: '
            '{}'.format(SUPPORTED_LEAGUES))
        return
    elif args.league.upper() not in SUPPORTED_LEAGUES:
        print(
            'League {} not supported. Please, use -l or --league and select a league to work on from the following '
            'list: {}'.format(args.league.upper(), SUPPORTED_LEAGUES))

    if args.patch:
        if not PATCH_PATTERN.match(args.patch):
            print(
                'Patch format is incorrect. Should be something like this:  \'8.9.1\', \'8.9\', \'8\' '
                '(withouth the \' symbols).')
            return

    if not args.output:
        args.output = 'XLSX'
        print('No output selected. Default output will be used (XLSX).')

    if not args.connector:
        print(
            'No connector selected. To select a connector write down one of the following names just after the '
            'script call with region and league parameters set: {}. Something like that: \"python program.py '
            '-r EUW -l SOLOQ -c {}\"'.format(SUPPORTED_CONNECTORS,
                                             SUPPORTED_CONNECTORS[0]))
        return
    elif args.connector.upper() == 'FS':
        filesystem.parse_args(args)
    elif args.connector.upper() == 'DB':
        database.parse_args(args, API_KEY)
    else:
        print('That connector is not supported.')
        return
Exemplo n.º 2
0
    def download_games(self, current_game_ids, new_game_ids):
        def tournament_match_to_dict(id1, hash1, tournament):
            with urllib.request.urlopen(TOURNAMENT_GAME_ENDPOINT.format(tr=tournament, id=id1, hash=hash1)) as url:
                match = json.loads(url.read().decode())
            with urllib.request.urlopen(TOURNAMENT_TL_ENDPOINT.format(tr=tournament, id=id1, hash=hash1)) as url:
                tl = json.loads(url.read().decode())
            return match, tl

        ids_not_in_db = self.get_new_ids(current_game_ids, new_game_ids)
        print('\t{} new games to be downloaded.'.format(len(ids_not_in_db)))
        if ids_not_in_db:
            for item in tqdm(ids_not_in_db, desc='\tDownloading games'):
                try:
                    if item[1] not in REGIONS.values():
                        match, timeline = tournament_match_to_dict(item[0], item[2], item[1])
                    else:
                        match = self.rw.match.by_id(match_id=item[0], region=item[1])
                        timeline = self.rw.match.timeline_by_match(match_id=item[0], region=item[1])
                    data = {'match': match, 'timeline': timeline}
                    self.__save_match_raw_data(data=data)
                except HTTPError:
                    pass
        else:
            print('\tAll games already downloaded.')
        return None
Exemplo n.º 3
0
 def save_static_data_files(self):
     # Versions
     region = [k for k, v in REGIONS.items() if v == self.region][0].lower()
     version = self.rw.data_dragon.versions_for_region(region=region)['v']
     db_versions = self.mongo_static_data.find_one({'type': 'versions'})
     if version not in db_versions['versions']:
         db_versions['versions'].insert(0, version)
         self.mongo_static_data.replace_one(filter={'type': 'versions'}, replacement=db_versions, upsert=True)
     items = self.rw.data_dragon.items(version=version)
     champs = self.rw.data_dragon.champions(version=version)
     summs = self.rw.data_dragon.summoner_spells(version=version)
     runes = {'runes': get_runes_reforged_json(version), 'type': 'runes'}
     self.mongo_static_data.replace_one(filter={'type': 'champion'}, replacement=champs, upsert=True)
     self.mongo_static_data.replace_one(filter={'type': 'item'}, replacement=items, upsert=True)
     self.mongo_static_data.replace_one(filter={'type': 'summoner'}, replacement=summs, upsert=True)
     self.mongo_static_data.replace_one(filter={'type': 'runes'}, replacement=runes, upsert=True)
Exemplo n.º 4
0
def parse_args():
    parser = argparse.ArgumentParser(description='LoL solution to generate datasets from leagues, scrims and Solo Q'
                                                 ' matches.')
    # Groups
    mandatory = parser.add_argument_group('Mandatory', 'Mandatory commands to run the program.')
    shared = parser.add_argument_group('Common', 'Shared commands for all systems.')
    filesystem = parser.add_argument_group('File system', 'Commands used for the file system.')
    databases = parser.add_argument_group('Databases', 'Commands used for the databases system.')

    # Mandatory commands
    mandatory.add_argument('-l', '--league', help='Choose league. {}'.format(SUPPORTED_LEAGUES))
    mandatory.add_argument('-r', '--region', help='Choose region. {}'.format(list(REGIONS.keys())))
    mandatory.add_argument('-c', '--connector', help='Choose between Databases (DB) or File System (FS) connectors. {}')

    # Shared commands
    shared.add_argument('-e', '--export', help='Export data.', action='store_true')
    shared.add_argument('-d', '--download', help='Download new data if available.', action='store_true')
    shared.add_argument('-usd', '--update_static_data', help='Update static data information.', action='store_true')
    shared.add_argument('-ng', '--n_games', help='Set the number of games to download from Solo Q.', type=int)
    shared.add_argument('-bi', '--begin_index', help='Set the begin index of the Solo Q downloads.', type=int)
    shared.add_argument('-ms', '--merge_soloq', help='Merge SoloQ data with info of players.', action='store_true')

    # FS commands
    filesystem.add_argument('-xlsx', help='Export data as XLSX.', action='store_true')
    filesystem.add_argument('-csv', help='Export data as CSV.', action='store_true')
    filesystem.add_argument('-fu', '--force_update', help='Force the update of the exports datasets.',
                                   action='store_true')

    # DB commands
    databases.add_argument('-ta', '--team_abbv', help='Work with the data of one or more teams selected through '
                                                      'his abbreviation. {download and export}')
    databases.add_argument('-bt', '--begin_time', help='Set the start date limit of the export (day-month-year). '
                                                       '{download and export}')
    databases.add_argument('-et', '--end_time', help='Set the end date limit of the export (day-month-year). '
                                                     '{download and export}')
    databases.add_argument('-p', '--patch', help='Select the patch. {export}')
    databases.add_argument('-C', '--competition', help='Select the competition. {download and export}')
    databases.add_argument('-s', '--split', help='Select the split [spring, summer]. {leagues data export only]')
    databases.add_argument('-S', '--season', help='Select the season [int]. {leagues data export only]')
    databases.add_argument('-R', '--region_filter', help='Select the region to download and export the data.')

    return parser.parse_args()