-
Notifications
You must be signed in to change notification settings - Fork 3
temp
Jae-Hwan edited this page Nov 30, 2021
·
5 revisions
home_pitchers =''' 투수명,이닝,피안타,실점,자책,4사구,삼진,피홈런,타자,타수,투구수,경기,승리,패전,세이브,평균자책 송승준,6,9,2,2,3,3,0,29,26,94,1,0,0,0,3.00 김이슬,0 1⁄3,0,0,0,0,0,0,1,1,6,1,0,0,0,0.00 이정민,0 2⁄3,0,0,0,0,0,0,1,1,1,1,1,0,0,0.00 강영식,1,0,0,0,0,2,0,3,3,10,1,0,0,0,0.00 애킨스,1,0,0,0,0,0,0,3,3,13,1,0,0,1,0.00 ''' home_pitchers_patch = {"송승준":{"등판":"선발"}, "이정민":{"결과": "승"}, "강영식": {"결과":"홀드"}, "애킨스": {"결과":"세"}, "팀": "롯데"} def changing_naver_pitchers_txt_to_csv(pitchers): pitchers_list = [] reader = csv.reader(pitchers.split('\n'), delimiter=',') for row in reader: pitchers_list.append(row) return pitchers_list def changing_naver_pitchers_col_name(pitchers_text): # 아래 첫번째 줄 코드는 트릭이다. 저장할 때 보기 좋게 하기 위해서 # 아래위로 엔터를 넣는데 그걸 제거하는 것이다. temp_pitchers = pitchers_text[1:-1] temp_pitchers = temp_pitchers.replace("투수명","선수명") temp_pitchers = temp_pitchers.replace("승리","승") temp_pitchers = temp_pitchers.replace("패전","패") temp_pitchers = temp_pitchers.replace("세이브","세") temp_pitchers = temp_pitchers.replace("피홈런","홈런") temp_pitchers = temp_pitchers.replace("평균자책","평균자책점") return temp_pitchers def changing_naver_pitchers_csv_to_json(pitchers_list, pitchers_patch): total_pitchers_list = [] for pitcher in pitchers_list[1:]: i = 0 temp_data = {} for item in pitcher: temp_data['팀'] = pitchers_patch['팀'] temp_data[pitchers_list[0][i]] = item i = i + 1 if temp_data['선수명'] in pitchers_patch.keys(): if len(pitchers_patch[temp_data['선수명']]) == 2: temp_data['등판'] = pitchers_patch[temp_data['선수명']]['등판'] temp_data['결과'] = pitchers_patch[temp_data['선수명']]['결과'] else: if '등판' in pitchers_patch[temp_data['선수명']]: temp_data['등판'] = pitchers_patch[temp_data['선수명']]['등판'] temp_data['결과'] = 0 else: temp_data['등판'] = 0 temp_data['결과'] = pitchers_patch[temp_data['선수명']]['결과'] total_pitchers_list.append(temp_data) return total_pitchers_list