def add2studydb(): """ Добавляет в базу данные для обучения """ db = get_studydb_cursor() matches = db.matches db2 = get_db_cursor() teams = db2.teams for champ in championats: for team1, score, team2 in grab_calendar(champ): data = {} print team1, score, team2 data.update({team1 + '_' + team2: {'score': score}}) data[team1 + '_' + team2].update({'meet': []}) for y in match_history(team1, team2): if y != [] and y[0] != u'Дата': print y[2] + '_' + y[5] + ':' + y[7] + '_' + y[4] data[team1 + '_' + team2]['meet'].append(y[2] + '_' + y[5] + ':' + y[7] + '_' + y[4]) tm1 = teams.find_one({'name': team1}) if not tm1: print('Команды с названием {0} нет :('.format(team1.encode('utf-8'))) else: print(team1) print() data[team1 + '_' + team2].update({team1: {}}) for name, dat in grab_team_static(tm1['uri'] + '?type=champ').items(): try: print(name + ': ' + dat) data[team1 + '_' + team2][team1].update({name: dat}) except TypeError: continue tm2 = teams.find_one({'name': team2}) if not tm2: print('Команды с названием {0} нет :('.format(team2.encode('utf-8'))) else: print() print(team2) print() data[team1 + '_' + team2].update({team2: {}}) for name, dat in grab_team_static(tm2['uri'] + '?type=champ').items(): try: print(name + ': ' + dat) data[team1 + '_' + team2][team2].update({name: dat}) except TypeError: continue matches.insert(data)
def main_out(team1, team2): def key_for_sort(x): if x[0] != None and x[1] != None: return len(x[0] + x[1]) print('#----------------------------------------- {0} - {1} ---------------------------#'.format(team1.encode('utf-8'), team2.encode('utf-8'))) for y in match_history(team1, team2): for x in y: print(x, end=' | ') print() db = get_db_cursor() teams = db.teams print('-*-'*20) tm1 = teams.find_one({'name': team1}) if not tm1: print('Команды с названием {0} нет :('.format(team1.encode('utf-8'))) else: print(team1) print("-"*40) for name, data in iter(sorted(grab_team_static(tm1['uri'] + '?type=champ').items(), key=key_for_sort)): try: print(name + ': ' + data) except TypeError: continue print('-*-'*20) tm2 = teams.find_one({'name': team2}) if not tm2: print('Команды с названием {0} нет :('.format(team2.encode('utf-8'))) else: print(team2) print("-"*40) for name, data in iter(sorted(grab_team_static(tm2['uri'] + '?type=champ').items(), key=key_for_sort)): try: print(name + ': ' + data) except TypeError: continue print('-*-'*20)