Spaces:
Running
Running
| import os | |
| import requests | |
| from datetime import datetime, timedelta | |
| from dotenv import load_dotenv | |
| from langchain_core.tools import tool | |
| load_dotenv() | |
| DATA4LIBRARY_KEY = os.getenv("LIBRARY_API_KEY", "") | |
| NAVER_CLIENT_ID = os.getenv("NAVER_CLIENT_ID", "") | |
| NAVER_CLIENT_SECRET = os.getenv("NAVER_CLIENT_SECRET", "") | |
| def search_library(district_name: str) -> str: | |
| """ | |
| ์ฌ์ฉ์๊ฐ ๋์๊ด ์์น๋ฅผ ๋ฌผ์ด๋ณผ ๋ ํธ์ถํฉ๋๋ค. | |
| ์ฃผ์: ๋ฐ๋์ ์์ธ์ '๊ตฌ' ๋จ์ ์ด๋ฆ(์: ๊ฐ๋จ๊ตฌ, ์์ด๊ตฌ, ๋งํฌ๊ตฌ)์ ์ ๋ ฅํด์ผ ํฉ๋๋ค. | |
| ๋ง์ฝ ์ฌ์ฉ์๊ฐ '์ผ์ฑ๋'์ฒ๋ผ '๋' ๋จ์๋ฅผ ๋ฌผ์ด๋ณด๋ฉด, ๋น์ (AI)์ด ํด๋น ๋์ด ์ํ '๊ตฌ'๋ฅผ ์ ์ถํด์ ์ ๋ ฅํ์ธ์. (์: ์ผ์ฑ๋ -> ๊ฐ๋จ๊ตฌ) | |
| """ | |
| region_codes = { | |
| "์ข ๋ก๊ตฌ": "11010", "์ค๊ตฌ": "11020", "์ฉ์ฐ๊ตฌ": "11030", "์ฑ๋๊ตฌ": "11040", | |
| "๊ด์ง๊ตฌ": "11050", "๋๋๋ฌธ๊ตฌ": "11060", "์ค๋๊ตฌ": "11070", "์ฑ๋ถ๊ตฌ": "11080", | |
| "๊ฐ๋ถ๊ตฌ": "11090", "๋๋ด๊ตฌ": "11100", "๋ ธ์๊ตฌ": "11110", "์ํ๊ตฌ": "11120", | |
| "์๋๋ฌธ๊ตฌ": "11130", "๋งํฌ๊ตฌ": "11140", "์์ฒ๊ตฌ": "11150", "๊ฐ์๊ตฌ": "11160", | |
| "๊ตฌ๋ก๊ตฌ": "11170", "๊ธ์ฒ๊ตฌ": "11180", "์๋ฑํฌ๊ตฌ": "11190", "๋์๊ตฌ": "11200", | |
| "๊ด์ ๊ตฌ": "11210", "์์ด๊ตฌ": "11220", "๊ฐ๋จ๊ตฌ": "11230", "์กํ๊ตฌ": "11240", | |
| "๊ฐ๋๊ตฌ": "11250" | |
| } | |
| dtl_region = region_codes.get(district_name) | |
| if not dtl_region: | |
| return f"'{district_name}'์ ๋ํ ์ง์ญ ์ฝ๋๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค. ์์ธ์ '๊ตฌ' ๋จ์๋ก ์ ํํ ์ ๋ ฅ๋์๋์ง ํ์ธํ์ธ์." | |
| url = "http://data4library.kr/api/libSrch" | |
| params = { | |
| "authKey": DATA4LIBRARY_KEY, | |
| "region": "11", | |
| "dtl_region": dtl_region, | |
| "pageSize": 3, | |
| "format": "json" | |
| } | |
| try: | |
| response = requests.get(url, params=params) | |
| print("\n" + "โผ"*50) | |
| print("๐ก [๋์๊ด ๋ชฉ๋ก ์กฐํ API ํต์ ๋ก๊ทธ]") | |
| print(f"๐ ์ค์ ํธ์ถ๋ URL: {response.url}") | |
| print("โฒ"*50 + "\n") | |
| data = response.json() | |
| libs = data.get('response', {}).get('libs', []) | |
| if not libs: | |
| return f"{district_name} ๊ทผ์ฒ์ ๋์๊ด ์ ๋ณด๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค." | |
| result = [] | |
| for item in libs: | |
| lib = item['lib'] | |
| name = lib.get('libName', '์ด๋ฆ ์์') | |
| lib_code = lib.get('libCode', '์ฝ๋ ์์') | |
| address = lib.get('address', '์ฃผ์ ์์') | |
| operating_time = lib.get('operatingTime', '์ด์์๊ฐ ์ ๋ณด ์์') | |
| result.append(f"- {name} (๋์๊ด ์ฝ๋: {lib_code})\n ์ฃผ์: {address}\n ์ด์์๊ฐ: {operating_time}") | |
| return "\n\n".join(result) | |
| except Exception as e: | |
| return f"API ํธ์ถ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}" | |
| def check_book_availability(lib_code: str, isbn13: str) -> str: | |
| """ | |
| ์ฌ์ฉ์๊ฐ ํน์ ๋์๊ด์์ ํน์ ์ฑ ์ '์ง๊ธ ๋น๋ฆด ์ ์๋์ง', '๋์ถ ๊ฐ๋ฅํ์ง' ๋ฌผ์ด๋ณผ ๋ ํธ์ถํฉ๋๋ค. | |
| ์ฃผ์: ์ด ๋๊ตฌ๋ฅผ ์ฌ์ฉํ๋ ค๋ฉด ๋จผ์ ๋์ ๋์๊ด์ ์ฝ๋(lib_code)์ ์ฑ ์ ISBN(isbn13)์ ์๊ณ ์์ด์ผ ํฉ๋๋ค. | |
| """ | |
| url = "http://data4library.kr/api/bookExist" | |
| params = { | |
| "authKey": DATA4LIBRARY_KEY, | |
| "libCode": lib_code, | |
| "isbn13": isbn13, | |
| "format": "json" | |
| } | |
| try: | |
| response = requests.get(url, params=params) | |
| print("\n" + "โผ"*50) | |
| print("๐ก [๋์ถ ๊ฐ๋ฅ ์ฌ๋ถ ์กฐํ API ํต์ ๋ก๊ทธ]") | |
| print(f"๐ ์ค์ ํธ์ถ๋ URL: {response.url}") | |
| print("โฒ"*50 + "\n") | |
| data = response.json() | |
| result_data = data.get('response', {}).get('result', {}) | |
| has_book = result_data.get('hasBook') | |
| loan_available = result_data.get('loanAvailable') | |
| if has_book == "N": | |
| return "ํด๋น ๋์๊ด์๋ ์ด ์ฑ ์ด ์์ฅ๋์ด ์์ง ์์ต๋๋ค." | |
| elif has_book == "Y" and loan_available == "Y": | |
| return "ํ์ฌ ๋์ถ ๊ฐ๋ฅํฉ๋๋ค! (์ ์ผ ๊ธฐ์ค ๋ฐ์ดํฐ์ด๋ฏ๋ก ๋ฐฉ๋ฌธ ์ ํ์ธ ๊ถ์ฅ)" | |
| elif has_book == "Y" and loan_available == "N": | |
| return "์์ฅ ์ค์ด๋ ํ์ฌ ๋๊ตฐ๊ฐ ๋์ถ ์ค์ ๋๋ค. ์์ฝ์ด ํ์ํ ์ ์์ต๋๋ค." | |
| else: | |
| return "์ํ ์ ๋ณด๋ฅผ ํ์ธํ ์ ์์ต๋๋ค." | |
| except Exception as e: | |
| return f"๋์ถ ๊ฐ๋ฅ ์ฌ๋ถ ํ์ธ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}" | |
| def check_book_availability_in_district(district_name: str, isbn13: str) -> str: | |
| """ | |
| ํน์ ๊ตฌ(์: ๊ฐ๋จ๊ตฌ)์ ๋์๊ด๋ค์์ ํน์ ์ฑ ์ ๋์ถ ๊ฐ๋ฅ ์ฌ๋ถ๋ฅผ ํ ๋ฒ์ ํ์ธํฉ๋๋ค. | |
| district_name์ ์์ธ์ '๊ตฌ' ๋จ์(์: ๊ฐ๋จ๊ตฌ, ๋งํฌ๊ตฌ), isbn13์ ์ฑ ์ 13์๋ฆฌ ISBN์ ๋๋ค. | |
| """ | |
| region_codes = { | |
| "์ข ๋ก๊ตฌ": "11010", "์ค๊ตฌ": "11020", "์ฉ์ฐ๊ตฌ": "11030", "์ฑ๋๊ตฌ": "11040", | |
| "๊ด์ง๊ตฌ": "11050", "๋๋๋ฌธ๊ตฌ": "11060", "์ค๋๊ตฌ": "11070", "์ฑ๋ถ๊ตฌ": "11080", | |
| "๊ฐ๋ถ๊ตฌ": "11090", "๋๋ด๊ตฌ": "11100", "๋ ธ์๊ตฌ": "11110", "์ํ๊ตฌ": "11120", | |
| "์๋๋ฌธ๊ตฌ": "11130", "๋งํฌ๊ตฌ": "11140", "์์ฒ๊ตฌ": "11150", "๊ฐ์๊ตฌ": "11160", | |
| "๊ตฌ๋ก๊ตฌ": "11170", "๊ธ์ฒ๊ตฌ": "11180", "์๋ฑํฌ๊ตฌ": "11190", "๋์๊ตฌ": "11200", | |
| "๊ด์ ๊ตฌ": "11210", "์์ด๊ตฌ": "11220", "๊ฐ๋จ๊ตฌ": "11230", "์กํ๊ตฌ": "11240", | |
| "๊ฐ๋๊ตฌ": "11250" | |
| } | |
| dtl_region = region_codes.get(district_name) | |
| if not dtl_region: | |
| return f"'{district_name}'์ ๋ํ ์ง์ญ ์ฝ๋๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค." | |
| # โโ 1. ๋์๊ด ๋ชฉ๋ก ์กฐํ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| try: | |
| lib_resp = requests.get("http://data4library.kr/api/libSrch", params={ | |
| "authKey": DATA4LIBRARY_KEY, | |
| "region": "11", | |
| "dtl_region": dtl_region, | |
| "pageSize": 3, | |
| "format": "json", | |
| }) | |
| print("\n" + "โผ"*50) | |
| print("๐ก [๋์๊ด ๋ชฉ๋ก ์กฐํ API]") | |
| print(f"๐ URL: {lib_resp.url}") | |
| print("โฒ"*50 + "\n") | |
| libs = lib_resp.json().get("response", {}).get("libs", []) | |
| except Exception as e: | |
| return f"๋์๊ด ๋ชฉ๋ก ์กฐํ ์ค ์ค๋ฅ: {e}" | |
| if not libs: | |
| return f"{district_name} ๊ทผ์ฒ์ ๋์๊ด ์ ๋ณด๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค." | |
| # โโ 2. ๊ฐ ๋์๊ด๋ณ ๋์ถ ๊ฐ๋ฅ ์ฌ๋ถ ํ์ธ โโโโโโโโโโโโโโโโโโ | |
| results = [] | |
| for item in libs: | |
| lib = item["lib"] | |
| lib_name = lib.get("libName", "์ด๋ฆ ์์") | |
| lib_code = lib.get("libCode", "") | |
| try: | |
| avail_resp = requests.get("http://data4library.kr/api/bookExist", params={ | |
| "authKey": DATA4LIBRARY_KEY, | |
| "libCode": lib_code, | |
| "isbn13": isbn13, | |
| "format": "json", | |
| }) | |
| print("\n" + "โผ"*50) | |
| print(f"๐ก [๋์ถ ๊ฐ๋ฅ ์ฌ๋ถ ์กฐํ API] {lib_name}") | |
| print(f"๐ URL: {avail_resp.url}") | |
| print("โฒ"*50 + "\n") | |
| result_data = avail_resp.json().get("response", {}).get("result", {}) | |
| has_book = result_data.get("hasBook") | |
| loan_available = result_data.get("loanAvailable") | |
| if has_book == "N": | |
| status = "๋ฏธ์์ฅ" | |
| elif has_book == "Y" and loan_available == "Y": | |
| status = "๋์ถ ๊ฐ๋ฅ" | |
| elif has_book == "Y" and loan_available == "N": | |
| status = "๋์ถ ์ค (์์ฝ ํ์)" | |
| else: | |
| status = "ํ์ธ ๋ถ๊ฐ" | |
| except Exception as e: | |
| status = f"์ค๋ฅ: {e}" | |
| results.append(f"- {lib_name}: {status}") | |
| return "\n".join(results) | |
| def get_popular_books(age: str = None, gender: str = None) -> str: | |
| """ | |
| ์ฌ์ฉ์๊ฐ '์์ฆ ์ธ๊ธฐ ์๋ ์ฑ ', '๋ฒ ์คํธ์ ๋ฌ', '๋ง์ด ์ฝ๋ ์ฑ ' ๋ฑ์ ์ถ์ฒํด๋ฌ๋ผ๊ณ ํ ๋ ํธ์ถํฉ๋๋ค. | |
| ์ง๋ฌธ์์ ์ฐ๋ น๋๋ ์ฑ๋ณ์ด ํ์ ๋๋ค๋ฉด ํด๋น ์ฝ๋๋ฅผ ์ธ์(ํ๋ผ๋ฏธํฐ)๋ก ๋ฐ๋์ ๋๊ฒจ์ฃผ์ธ์. | |
| - age: "0"(์์ ์), "6"(์ ์), "8"(์ด๋ฑ), "14"(์ฒญ์๋ ), "20"(20๋), "30"(30๋), "40"(40๋), "50"(50๋), "60"(60์ธ ์ด์) | |
| - gender: "0"(๋จ์ฑ), "1"(์ฌ์ฑ) | |
| """ | |
| url = "http://data4library.kr/api/loanItemSrch" | |
| params = { | |
| "authKey": DATA4LIBRARY_KEY, | |
| "format": "json", | |
| "pageSize": 5 | |
| } | |
| if age: | |
| params["age"] = age | |
| if gender: | |
| params["gender"] = gender | |
| try: | |
| response = requests.get(url, params=params) | |
| print("\n" + "โผ"*50) | |
| print("๐ก [์ธ๊ธฐ ๋์ถ ๋์ ์กฐํ API ํต์ ๋ก๊ทธ]") | |
| print(f"๐ ์ค์ ํธ์ถ๋ URL: {response.url}") | |
| print("โฒ"*50 + "\n") | |
| data = response.json() | |
| docs = data.get('response', {}).get('docs', []) | |
| if not docs: | |
| return "์กฐ๊ฑด์ ๋ง๋ ์ธ๊ธฐ ๋์ ๋ฐ์ดํฐ๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค." | |
| result = [] | |
| for item in docs: | |
| doc = item['doc'] | |
| ranking = doc.get('ranking', '์์ ์์') | |
| bookname = doc.get('bookname', '์ ๋ชฉ ์์') | |
| authors = doc.get('authors', '์ ์ ๋ฏธ์') | |
| publisher = doc.get('publisher', '์ถํ์ฌ ๋ฏธ์') | |
| loan_count = doc.get('loan_count', '0') | |
| result.append(f"{ranking}์. {bookname}\n - ์ ์: {authors}\n - ์ถํ์ฌ: {publisher}\n - ๋์ ๋์ถ๊ฑด์: {loan_count}๊ฑด") | |
| condition_text = "์ ์ฒด ์ด์ฉ์" | |
| if age or gender: | |
| condition_text = f"์ ํ๋ ์กฐ๊ฑด(์ฐ๋ น:{age if age else '์ ์ฒด'}, ์ฑ๋ณ:{gender if gender else '์ ์ฒด'})์" | |
| return f"[{condition_text} ์ธ๊ธฐ ๋์ถ ๋์ ์์ 5๊ถ]\n\n" + "\n\n".join(result) | |
| except Exception as e: | |
| return f"์ธ๊ธฐ ๋์ API ํธ์ถ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}" | |
| def get_trending_books(search_date: str = None) -> str: | |
| """ | |
| ์ฌ์ฉ์๊ฐ '์์ฆ ๊ฐ์๊ธฐ ๋จ๋ ์ฑ ', '์ญ์ฃผํ ๋ฒ ์คํธ์ ๋ฌ', '๋์ถ ๊ธ์์น ๋์', '์ต๊ทผ ํธ๋ ๋'๋ฅผ ๋ฌผ์ด๋ณผ ๋ ํธ์ถํฉ๋๋ค. | |
| - search_date: 'YYYY-MM-DD' ํ์์ ๋ ์ง. | |
| ๋ง์ฝ ์ฌ์ฉ์๊ฐ ํน์ ๋ ์ง๋ฅผ ์ธ๊ธํ์ง ์์๋ค๋ฉด ์ด ํ๋ผ๋ฏธํฐ๋ฅผ ๋น์๋์ธ์(None). ์ฝ๋๊ฐ ์์์ ์ต๊ทผ ๋ ์ง๋ก ๊ฒ์ํฉ๋๋ค. | |
| """ | |
| if not search_date: | |
| yesterday = datetime.now() - timedelta(days=1) | |
| search_date = yesterday.strftime("%Y-%m-%d") | |
| url = "http://data4library.kr/api/hotTrend" | |
| params = { | |
| "authKey": DATA4LIBRARY_KEY, | |
| "searchDt": search_date, | |
| "format": "json" | |
| } | |
| try: | |
| response = requests.get(url, params=params) | |
| print("\n" + "โผ"*50) | |
| print("๐ก [๊ธ์์น ๋์ ์กฐํ API ํต์ ๋ก๊ทธ]") | |
| print(f"๐ ์ค์ ํธ์ถ๋ URL: {response.url}") | |
| print("โฒ"*50 + "\n") | |
| data = response.json() | |
| results = data.get('response', {}).get('results', []) | |
| if not results: | |
| return f"{search_date} ๊ธฐ์ค ๊ธ์์น ๋์ ๋ฐ์ดํฐ๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค." | |
| target_date_data = results[0]['result'] | |
| actual_date = target_date_data.get('date', search_date) | |
| docs = target_date_data.get('docs', []) | |
| if not docs: | |
| return f"{actual_date} ๊ธฐ์ค ๊ธ์์น ๋์๊ฐ ์์ต๋๋ค." | |
| formatted_result = [] | |
| for item in docs: | |
| doc = item['doc'] | |
| no = doc.get('no', '0') | |
| bookname = doc.get('bookname', '์ ๋ชฉ ์์') | |
| authors = doc.get('authors', '์ ์ ๋ฏธ์') | |
| difference = doc.get('difference', '0') | |
| formatted_result.append(f"{no}์. {bookname} (์ ์: {authors}) \n ๐ฅ ๋ฌด๋ ค {difference}๊ณ๋จ ๋์ถ ์์ ์์น!") | |
| return f"[{actual_date} ๊ธฐ์ค ๋์ถ ๊ธ์์น ๋์ TOP 5]\n\n" + "\n\n".join(formatted_result) | |
| except Exception as e: | |
| return f"๊ธ์์น ๋์ API ํธ์ถ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}" | |
| def get_book_recommendations(isbn13: str) -> str: | |
| """ | |
| ์ฌ์ฉ์๊ฐ ํน์ ์ฑ (์: ์ฑ์์ฃผ์์, ์๋ ์ด ์จ๋ค ๋ฑ)์ ์ธ๊ธํ๋ฉฐ '๋น์ทํ ์ฑ ', '๊ฐ์ด ์ฝ๊ธฐ ์ข์ ์ฑ ', '์ด ์ฑ ์ ์ฝ์ ์ฌ๋๋ค์ด ์ข์ํ๋ ์ฑ '์ ์ถ์ฒํด๋ฌ๋ผ๊ณ ํ ๋ ํธ์ถํฉ๋๋ค. | |
| ์ฃผ์: ์ด ๋๊ตฌ๋ฅผ ์ฌ์ฉํ๋ ค๋ฉด ๋ฐ๋์ ํด๋น ์ฑ ์ 13์๋ฆฌ ISBN ๋ฒํธ๊ฐ ํ์ํฉ๋๋ค. | |
| ๋ง์ฝ ISBN์ ๋ชจ๋ฅธ๋ค๋ฉด ์ฑ ๊ฒ์ ๋๊ตฌ๋ฅผ ๋จผ์ ์ฌ์ฉํด์ ISBN์ ์์๋ธ ๋ค ์ด ๋๊ตฌ๋ฅผ ํธ์ถํ์ธ์. | |
| """ | |
| url = "http://data4library.kr/api/usageAnalysisList" | |
| params = { | |
| "authKey": DATA4LIBRARY_KEY, | |
| "isbn13": isbn13, | |
| "format": "json" | |
| } | |
| try: | |
| response = requests.get(url, params=params) | |
| print("\n" + "โผ"*50) | |
| print("๐ก [์ฐ๊ด ๋์ ์ถ์ฒ API ํต์ ๋ก๊ทธ]") | |
| print(f"๐ ์ค์ ํธ์ถ๋ URL: {response.url}") | |
| print("โฒ"*50 + "\n") | |
| data = response.json() | |
| response_data = data.get('response', {}) | |
| co_loan_books = response_data.get('coLoanBooks', []) | |
| mania_rec_books = response_data.get('maniaRecBooks', []) | |
| if not co_loan_books and not mania_rec_books: | |
| return "ํด๋น ๋์์ ์ฐ๊ด๋ ์ถ์ฒ ๋์ ๋ฐ์ดํฐ๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค." | |
| result_text = [] | |
| if co_loan_books: | |
| result_text.append("๐ [์ด ์ฑ ์ ๋น๋ฆฐ ์ฌ๋๋ค์ด ํจ๊ป ๋น๋ฆฐ ์ฑ ]") | |
| for i, item in enumerate(co_loan_books[:3]): | |
| book = item['book'] | |
| result_text.append(f" {i+1}. {book.get('bookname', '์ ๋ชฉ ์์')} (์ ์: {book.get('authors', '์ ์ ๋ฏธ์')})") | |
| if mania_rec_books: | |
| result_text.append("\n๐ก [์ด ์ฑ ์ ๋ง๋์๋ค์ ์ํ ๋ง์ถค ์ถ์ฒ]") | |
| for i, item in enumerate(mania_rec_books[:3]): | |
| book = item['book'] | |
| result_text.append(f" {i+1}. {book.get('bookname', '์ ๋ชฉ ์์')} (์ ์: {book.get('authors', '์ ์ ๋ฏธ์')})") | |
| return "\n".join(result_text) | |
| except Exception as e: | |
| return f"์ฐ๊ด ๋์ ์ถ์ฒ API ํธ์ถ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}" | |
| def get_book_isbn(book_title: str) -> str: | |
| """ | |
| ์ฌ์ฉ์๊ฐ ์ธ๊ธํ ์ฑ ์ ๋ชฉ์ผ๋ก 13์๋ฆฌ ISBN ๋ฒํธ์ ํ์ง ์ด๋ฏธ์ง ๋งํฌ๋ฅผ ๊ฒ์ํ ๋ ํธ์ถํฉ๋๋ค. | |
| ๋ค์ด๋ฒ ์ฑ ๊ฒ์ API๋ฅผ ์ฌ์ฉํ์ฌ ์ตํต์ฑ ์๊ณ ์ ํํ๊ฒ ๋ฐ์ดํฐ๋ฅผ ์ฐพ์์ต๋๋ค. | |
| """ | |
| url = "https://openapi.naver.com/v1/search/book.json" | |
| headers = { | |
| "X-Naver-Client-Id": NAVER_CLIENT_ID, | |
| "X-Naver-Client-Secret": NAVER_CLIENT_SECRET, | |
| } | |
| params = {"query": book_title, "display": 1} | |
| try: | |
| response = requests.get(url, headers=headers, params=params) | |
| print("\n" + "โผ"*50) | |
| print("๐ก [ISBN + ํ์ง URL ๊ฒ์ API ํต์ ๋ก๊ทธ]") | |
| print(f"๐ ์ค์ ํธ์ถ๋ URL: {response.url}") | |
| print("โฒ"*50 + "\n") | |
| data = response.json() | |
| items = data.get('items', []) | |
| if not items: | |
| return f"'{book_title}'์ ๋ํ ์ฑ ์ ๋ณด๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค." | |
| isbn_raw = items[0].get('isbn', '') | |
| isbn13 = isbn_raw.split()[-1] if isbn_raw else "" | |
| full_title = items[0].get('title', book_title) | |
| author = items[0].get('author', '์ ์ ๋ฏธ์') | |
| image_url = items[0].get('image', '') | |
| return f"์ฑ '{full_title}' (์ ์: {author})์ ์ ํํ ISBN13 ๋ฒํธ๋ '{isbn13}' ์ด๋ฉฐ, ํ์ง ์ด๋ฏธ์ง ๋งํฌ๋ '{image_url}' ์ ๋๋ค. ๋ฉ์์ง ์ถ๋ ฅ ์ ์ด ์ด๋ฏธ์ง๋ฅผ ๋ฐ๋์ ๋งํฌ๋ค์ด์ผ๋ก ๋ณด์ฌ์ฃผ์ธ์." | |
| except Exception as e: | |
| return f"๋ค์ด๋ฒ ISBN ๊ฒ์ API ํธ์ถ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}" | |