Open kyohoonsim opened 1 year ago
from sqlalchemy import create_engine, text
db_connection_info = {
'user': 'root',
'password': 'asdf1234!',
'host': 'localhost',
'port': 3306,
'database': 'lahmansbaseballdb'
}
db_url = f"mysql+mysqlconnector://{db_connection_info['user']}:{db_connection_info['password']}@{db_connection_info['host']}:{db_connection_info['port']}/{db_connection_info['database']}?charset=utf8"
engine = create_engine(db_url, max_overflow=0)
def read_player_pitching_data(playerID: str):
'''선수ID를 입력받아 투수 데이터를 반환해주는 함수'''
with engine.connect() as conn:
rows = conn.execute(text("select * from pitching where playerID = :playerID"), {'playerID': playerID})
row_list = [row for row in rows]
return row_list
if __name__ == "__main__": #엔트리 포인트
kim_pitching_data = read_player_pitching_data('kimby01')
print(kim_pitchting_data)
def read_player_pitching_data(playerID: str):
with engine.connect() as conn:
rows = conn.execute(text("select * from pitching where playerID=:playerID"), {
'playerID': playerID
})
row_list = [row for row in rows]
return row_list
#Entry Point
if __name__ == "__main__":
ryu_data = read_player_pitching_data('ryuhy01')
for row in ryu_data:
print(row)
print("hello")
''' print("hello") '''
from sqlalchemy import create_engine, text
db_connection_info = {
'user' : 'root',
'password' : 'asdf1234!',
'host' : '127.0.0.1', #localhost
'port' : 3306,
'database': 'lahmansbaseballdb'
}
db_url = f"mysql+mysqlconnector://{db_connection_info['user']}:{db_connection_info['password']}@{db_connection_info['host']}:{db_connection_info['port']}/{db_connection_info['database']}"
engine = create_engine(db_url, max_overflow=0)
def read_player_pitching_data(playerID) :
'''선수ID를 입력받아 피칭 데이터를 반화내주는 함수'''
with engine.connect() as conn:
rows = conn.execute(text("SELECT * FROM pitching WHERE playerID = :playerID"), {'playerID' : playerID})
row_list = [row for row in rows]
return row_list
if __name__ == "__main__" : #엔트리 포인트
ryu_pitching_data = read_player_pitching_data('ryuhy01')
print(ryu_pitching_data)
def read_player_pitching_data(playerID:str):
with engine.connect() as conn:
rows = conn.execute(text("select * from pitching where playerID = :playerID"), {'playerID': playerID})
row_list = [row for row in rows]
return row_list
if __name__ == "__main__": # 엔트리 포인트
ryu_pitching_data= read_player_pitching_data('ryuhy01')
print(ryu_pitching_data)
def read_player_batting_data(playerID: str):
with engine.connect() as conn:
rows = conn.execute(text("select * from batting where playerID = :playerID"), {'playerID': playerID})
row_list = [row for row in rows]
return row_list
def read_player_pitching_data(playerID: str):
with engine.connect() as conn:
rows = conn.execute(text("select * from pitching where playerID = :playerID"), {'playerID': playerID})
row_list = [row for row in rows]
return row_list
if __name__ == "__main__":
#choo_batting_data = read_player_batting_data('choosh01')
#print(choo_batting_data)
#kang_batting_data = read_player_batting_data('kangju01')
#print(kang_batting_data)
ryu_peaching_data = read_player_pitching_data('ryuhy01')
print(ryu_peaching_data)
`
def read_player_pitching_data(playerID: str):
'''선수 ID를 입력받아 투구 데이터를 반환해주는 함수'''
with engine.connect() as conn:
rows = conn.execute(text("SELECT * FROM pitching WHERE playerID = :playerID"), {'playerID': playerID})
row_list = [row for row in rows]
return row_list
if __name__ == "__main__": # 앤트리 포인트
ryu_pitching_data = read_player_pitching_data('ryuhy01')
print(ryu_pitching_data)
... from sqlalchemy import create_engine, text
db_connection_info = { 'user': 'root', 'password': 'asdf1234!', 'host': 'localhost', 'port': 3306, 'database': 'lahmansbaseballdb' }
db_url =f"mysql+mysqlconnector://{db_connection_info['user']}:{db_connection_info['password']}@{db_connection_info['host']}:{db_connection_info['port']}/{db_connection_info['database']}"
print(db_url) engine = create_engine(db_url, max_overflow=0)
def read_player_batting_data(playerID: str): with engine.connect() as conn: rows = conn.execute(text("select * from batting where playerID = :playerID"), {'playerID': playerID})
def read_player_pitching_data(playerID: str): with engine.connect() as conn: rows = conn.execute(text("select * from pitching where playerID = :playerID"), {'playerID': playerID})
row_list = [row for row in rows]
return row_list
if name == "main": choo_data = read_player_batting_data('choosh01') print(choo_data)
kang_data = read_player_batting_data('kangju01')
print(kang_data)
pitcher_data = read_player_pitching_data('ryuhy01')
print(pitcher_data)
...
from sqlalchemy import create_engine, text
db_connection_info = {
'user': 'root',
'password': 'asdf1234!',
'host': 'localhost',
'port': 3306,
'database': 'lahmansbaseballdb'
}
db_url = f"mysql+mysqlconnector://{db_connection_info['user']}:{db_connection_info['password']}@{db_connection_info['host']}:{db_connection_info['port']}/{db_connection_info['database']}?charset=utf8"
engine = create_engine(db_url, max_overflow=0)
def read_player_pitching_data(playerID: str):
'''선수 ID를 입력하면 투수 데이터 반환'''
with engine.connect() as conn:
rows = conn.execute(text("select * from pitching where playerID = :playerID"), {'playerID': playerID})
row_list = [row for row in rows]
return row_list
if __name__ == "__main__":
ryu_data = read_player_pitching_data('ryuhy01')
print(ryu_data)
def read_player_pitching_data(playerID: str): with engine.connect() as conn: rows = conn.execute(text("select * from pitching where playerID=:playerID"), { 'playerID': playerID }) row_list = [row for row in rows] return row_list
if name == "main": ryu_data = read_player_pitching_data('ryuhy01') for row in ryu_data: print(row)
def read_player_pitching_data(playerID: str):
'''선수ID를 입력받아 투구 데이터를 반환해주는 함수'''
with engine.connect() as conn:
rows = conn.execute(text("SELECT * FROM pitching WHERE playerID = :playerID"), {'playerID': playerID})
row_list = [row for row in rows]
return row_list
if __name__ == "__main__": # 엔트리 포인트
kim_pitching_data = read_player_pitching_data('kimby01')
print(kim_pitching_data)
def read_player_pitching_data(playerID:str):
'''선수 아이디를 입력받아 투수 데이터 변환해주는 함수'''
with engine.connect() as conn:
rows = conn.execute(text("select * from pitching where playerID = :playerID"), {'playerID': playerID})
row_list = [row for row in rows]
return row_list
if __name__ == "__main__": #엔트리 포인트
choo_batting_data = read_player_batting_data('choosh01')
print(choo_batting_data)
kang_batting_data = read_player_batting_data('kangju01')
print(kang_batting_data)
ryu_pitching_data = read_player_pitching_data('ryuhy01')
print(ryu_pitching_data)
def read_player_pitching_data(playerID: str):
'''선수ID를 입력받아 피칭 데이터를 반환해주는 함수'''
with engine.connect() as conn:
rows = conn.execute(text("SELECT * FROM pitching WHERE playerID = :playerID"), {'playerID': playerID})
row_list = [row for row in rows]
return row_list
if __name__ == "__main__": # 엔트리 포인트
ryu_pitching_data = read_player_pitching_data('ryuhy01')
print(ryu_pitching_data)
def read_player_pitching_data(playerID: str):
'''선수ID를 입력받아 투수 데이터를 반환해주는 함수'''
with engine.connect() as conn:
rows = conn.execute(text("select * from pitching where playerID = :playerID"), {'playerID': playerID})
row_list = [row for row in rows]
return row_list
if __name__ == "__main__":
ryu_pitching_data = read_player_pitching_data('ryuhy01')
print(ryu_pitching_data)
from sqlalchemy import create_engine, text
db_connection_info = { 'user': 'root', 'password': 'asdf1234!', 'host': 'localhost', 'port': 3306, 'database': 'lahmansbaseballdb' }
db_url = f"mysql+mysqlconnector://{db_connection_info['user']}:{db_connection_info['password']}@{db_connection_info['host']}:{db_connection_info['port']}/{db_connection_info['database']}?charset=utf8" engine = create_engine(db_url, max_overflow=0)
def read_player_pitching_data(playerID: str): with engine.connect() as conn: rows = conn.execute(text("select * from pitching where playerID = :playerID"), {'playerID': playerID})
row_list = [row for row in rows]
return row_list
if name == "main":
ryu_data = read_player_pitching_data('ryuhy01')
print(ryu_data)
from sqlalchemy import create_engine, text
db_connection_info = {
'user': 'root',
'password': 'asdf1234!',
'host': 'localhost', # localhost
'port': 3306,
'database': 'lahmansbaseballdb'
}
db_url = f"mysql+mysqlconnector://{db_connection_info['user']}:{db_connection_info['password']}@{db_connection_info['host']}:{db_connection_info['port']}/{db_connection_info['database']}"
engine = create_engine(db_url, max_overflow=0)
def read_player_pitching_data(playerID: str):
with engine.connect() as conn:
rows = conn.execute(text("select * from pitching where playerID = :playerID"), {'playerID': playerID})
row_list = [row for row in rows]
return row_list
if __name__ == "__main__":
ryu_pitching_data = read_player_pitching_data('ryuhy01')
print(ryu_pitching_data)
from sqlalchemy import create_engine, text
db_connection_info = { 'user': 'root', 'password': 'asdf1234!', 'host': 'localhost', 'port': 3306, 'database': 'lahmansbaseballdb' }
db_url = f"mysql+mysqlconnector://{db_connection_info['user']}:\ {db_connection_info['password']}@{db_connection_info['host']}:\ {db_connection_info['port']}/{db_connection_info['database']}?charset=utf8" engine = create_engine(db_url, max_overflow=0)
def read_player_pitching_data(playerID: str): with engine.connect() as conn: rows = conn.execute(text("select *\ from pitching where playerID = :playerID"),{'playerID' : playerID})
row_list = [row for row in rows]
return row_list
if name == "main": ryu_data = read_player_pitching_data('ryuhy01') print(ryu_data)
소스코드 및 실행결과 캡쳐 화면 제출