From 65065442a1e639c9af449ac019d1149076113616 Mon Sep 17 00:00:00 2001 From: "Arin(asus)" Date: Wed, 3 Sep 2025 20:28:34 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B3=A0=EC=B0=BD=EA=B5=B0=EB=A6=BD=EB=8F=84?= =?UTF-8?q?=EC=84=9C=EA=B4=80=20=EA=B2=80=EC=83=89=EA=B8=B0=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20=EB=B0=8F=20=EB=9D=BC=EC=9D=B4=EC=84=A0=EC=8A=A4=20?= =?UTF-8?q?=EA=B8=B0=EA=B0=84=20=EC=97=B0=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - GochangLibSearcher.cs: 고창군립도서관 HTTP API 검색기 추가 - 고창군립도서관 및 산하 9개 분관 검색 대상에 등록 - 라이선스 기간 2025.12.30까지 연장 - 어셈블리 버전 2025.09.03.2030으로 업데이트 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .claude/settings.local.json | 8 +- .../ExcelTest.csproj.AssemblyReference.cache | Bin 809 -> 9064 bytes ...ExcelTest.csproj.ResolveComReference.cache | Bin 973 -> 498 bytes .../pofalApi_tmp.AssemblyInfo.cs | 2 +- .../pofalApi_tmp.AssemblyInfoInputs.cache | 2 +- .../netcoreapp3.1/pofalApi_tmp.assets.cache | Bin 148 -> 160 bytes unimarc/unimarc/Properties/AssemblyInfo.cs | 4 +- .../unimarc/SearchModel/GochangLibSearcher.cs | 303 ++++++++++++++++++ unimarc/unimarc/UniMarc.csproj | 1 + unimarc/unimarc/마크/Check_copyWD.cs | 18 +- 10 files changed, 331 insertions(+), 7 deletions(-) create mode 100644 unimarc/unimarc/SearchModel/GochangLibSearcher.cs diff --git a/.claude/settings.local.json b/.claude/settings.local.json index 4354a73..745f082 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -2,7 +2,13 @@ "permissions": { "allow": [ "Bash(git add:*)", - "WebFetch(domain:jnelib.jne.go.kr)" + "WebFetch(domain:jnelib.jne.go.kr)", + "Bash(node:*)", + "Bash(npm --version)", + "Bash(echo $OS)", + "Bash(claude mcp:*)", + "WebSearch", + "WebSearch" ], "deny": [], "ask": [] diff --git a/ExcelTest/ExcelTest/obj/Debug/ExcelTest.csproj.AssemblyReference.cache b/ExcelTest/ExcelTest/obj/Debug/ExcelTest.csproj.AssemblyReference.cache index d756ce86f5878bbf35f786403c46688e3d78aa35..c0667528d5c6590be72fe118b795da97793d91b8 100644 GIT binary patch literal 9064 zcmeHMUu+ab7{5_0rG*x#fFQ^bi7835*Otfj?HqH}J!_I1!b~f*9*&P8S6fqX$l}4~> zLv0Tu0>|Ay9W_KiHQRnLql|29yMEGn!l+cqInzRVAR71Q zX-H3Fk}{5&QXkW<8HnNS~c_Hn#ISCm-EBc z@e5nr`JEq+hGj3fnG!#YHr^V z>z!7SHjGTG;Eu5tb6ATlp6#%9Cc@VC{86v7+p2r=`yn~r5@DgrV zBmT(j{`i>_iS;i|{yz5U?ME+U zB9og?Iyl-U$reSBRZTBj)!qT+Z72SGb=xlwZ*g8_ls##AmaHiK7iVe!8ul1AQF94s zTFjaWn#)>-!x={q+@^)gPv*M0j-$gCEXn3LH^p^kgHkH|SU$v=Au*w9F~bJKK$~5H z34^3@#-@;yl=czkhz#cD!^9D!=;9}KX?3r0DKpqn5uH*u@o--ehZRvQ{W=@ACG9#}e~HF;HH-Im9?hsU0FqvuAs>p0btM7WR3zYRNl;<}V57@iFR>8K zQfwkt_NK6kD%0YB1<^rU6^;hiO?YC)O1T*G>p zzFZW}J|0~oGRumKcs4Y1lkDA$%`N2j@ltf`vk6gLW%$9wNvs8}k=`sz&^OGc5-3*G z;ya&Qp~Y~JDai)R1}N_3(W!esop&my(kMHjTk{Vp)&KRgTG?T#A#G z*~H?L(lT>Wt@QQvovri(it^Ko5_1*YfI`Iz8Wk31n)+ZXAtY9d^$`~9LoC)uws>+M zn`Zq_Nk6%5*>$R=tKJF5J-k$XkYN&EVZam1N!Pw*{4B10vGe%4PVJ-}i*qkttX;TQAbX_j+5_bYEqTA5Kb6RP<1k&|@78ILf0#S0f6wdU%o=H)GW+QAV)5w2qh+GE z4t)44@KrnL-~F=2`1Ak1-ya+{h(7Szp1Ek#TYXhYyex YkZ=dFmArvuK93e3Fq|3wLjfZL04U6rF#rGn diff --git a/ExcelTest/ExcelTest/obj/Debug/ExcelTest.csproj.ResolveComReference.cache b/ExcelTest/ExcelTest/obj/Debug/ExcelTest.csproj.ResolveComReference.cache index c1808faff193e20e098609e11da75ce4eb440e75..5698e5e082d0676e39d5ca9302f51e0da7802df6 100644 GIT binary patch literal 498 zcmZQ$^l-L{2`I`>FG|c+aLdd|EmqK|urSk%@y$#w$}i4OD^Un`@h*-D&&*57FE5TM zGc?dMaEwXH%!~1J4RMQ5FwwJ62+7aSDW;-HEDQ_`jPgK-!E6n#EG|jSH8zSVE=kGH zNj1_d$w^`YDq@l;yO$nxhl4Q*-4{si_fJd9Oiqmn%Fi!}33CgE`4;S1=ltB<{JaP= z6D0M)8Hq)yDKY+TZl2DrhGsFo!Tx$KK0YA(G-{5EH$1t^!I(yweHK7d5#bB5FU-j? z28hjogsYirM2Mchj}ypF(}4)kn`Y!WCr9u2nSxAg2QW Doo%Tr literal 973 zcmb`F&2G~`5XYS+aq~e@1Xm<{KnO&%irXYal_J`>jvCb^rLmG6tfGxQCRW$pXm_2q zaN^b*ufc&6?||S9xbgrTkaz&t?FUpM<$zepvt!HipZWiGwTz}|Kjc!oS~r$tIM|JR zMmY@y>ZB0~kc;^tM;2vJHHN@=M3c7JKqji8TGg;pB2otJ1X95;sTzCfghc)hoVfH5 zlJ=yw7B<4ip=kz<8eYSB)eJ4}u@9V*IaoB_hY%PfK3LeFLQa<4_Gvt$2_(XeV&DSD zGk#N$NiUu`)Wz zgrjZDrvgt1EGZnttPHxEVB1>v_85J^aBL`9Zag?{H6MDvycmP69qx^yB%nv!o12o) zrZE_5A--%jeXDe>Ji!e<(Q=2VLw7%9bwx6eQ>wX22@SvPA=s z_U2Ilte`#&B&(b}N3IVsNr7uxHml|H<-(#~y-Tfo3yAjq(Es|Z^+Z=wmDFrSl@?W2 zQJI3R7i8#NLtOTXX>xuDSMg7!nZO%%Hr3OV!EV}P7xkTvUX*h7KgspG-JWHetKROQ zkG32~FG;EOYovbPg?<=DK6vMwthUFN?I3$>>t$JgSJq!%6bWq9A2sV97Xc-(isY@X qC>V-EVMTj;|MkZEPp2|#-J;(=o@MXM58uwRqxzRO8?Qc}mVW{hTQDO4 diff --git a/pofalApi_tmp/obj/Debug/netcoreapp3.1/pofalApi_tmp.AssemblyInfo.cs b/pofalApi_tmp/obj/Debug/netcoreapp3.1/pofalApi_tmp.AssemblyInfo.cs index f55ecd2..3534421 100644 --- a/pofalApi_tmp/obj/Debug/netcoreapp3.1/pofalApi_tmp.AssemblyInfo.cs +++ b/pofalApi_tmp/obj/Debug/netcoreapp3.1/pofalApi_tmp.AssemblyInfo.cs @@ -14,7 +14,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("pofalApi_tmp")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8e7df6f68d424e8b9f20e24f017b877849125171")] [assembly: System.Reflection.AssemblyProductAttribute("pofalApi_tmp")] [assembly: System.Reflection.AssemblyTitleAttribute("pofalApi_tmp")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/pofalApi_tmp/obj/Debug/netcoreapp3.1/pofalApi_tmp.AssemblyInfoInputs.cache b/pofalApi_tmp/obj/Debug/netcoreapp3.1/pofalApi_tmp.AssemblyInfoInputs.cache index 62b5dc1..f4d92b1 100644 --- a/pofalApi_tmp/obj/Debug/netcoreapp3.1/pofalApi_tmp.AssemblyInfoInputs.cache +++ b/pofalApi_tmp/obj/Debug/netcoreapp3.1/pofalApi_tmp.AssemblyInfoInputs.cache @@ -1 +1 @@ -c13c9c2f2e12bc007cbcab6ccdb94397f9d2465a +1e22963f41eb10ec8b7d5cf0f11446afcd4c7c64669758c39d9d6d7a2dc5abbf diff --git a/pofalApi_tmp/obj/Debug/netcoreapp3.1/pofalApi_tmp.assets.cache b/pofalApi_tmp/obj/Debug/netcoreapp3.1/pofalApi_tmp.assets.cache index edc0738dc43794e1c1519ce9792c6f8f40a3326e..9ef0e94f7cc81bdf6979e5a19ec707cd92da84f2 100644 GIT binary patch delta 61 zcmbQjxPVbJz}wxChk=3N^EpqwHxC4-cW$i|4u4*y9KVFG+rU!Q-XQJ8+6rFo&^Z$g Qr6)S@OmtwG=;Hw-0ihoiegFUf delta 49 zcmV-10M7rQ0h9qLP)kQa3IG5AsZDhPTxDJ@g3qL@68*o&Cn&lm=-xLsMbN~(m8qdd HkdZNKu%{GO diff --git a/unimarc/unimarc/Properties/AssemblyInfo.cs b/unimarc/unimarc/Properties/AssemblyInfo.cs index 369fb3d..d620c5a 100644 --- a/unimarc/unimarc/Properties/AssemblyInfo.cs +++ b/unimarc/unimarc/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를 // 기본값으로 할 수 있습니다. // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2025.08.19.2250")] -[assembly: AssemblyFileVersion("2025.08.19.2250")] +[assembly: AssemblyVersion("2025.09.03.2030")] +[assembly: AssemblyFileVersion("2025.09.03.2030")] diff --git a/unimarc/unimarc/SearchModel/GochangLibSearcher.cs b/unimarc/unimarc/SearchModel/GochangLibSearcher.cs new file mode 100644 index 0000000..90fb781 --- /dev/null +++ b/unimarc/unimarc/SearchModel/GochangLibSearcher.cs @@ -0,0 +1,303 @@ +using System; +using System.Threading.Tasks; +using OpenQA.Selenium; +using OpenQA.Selenium.Chrome; +using OpenQA.Selenium.Support.UI; +using System.Text.RegularExpressions; +using WebDriverManager; +using WebDriverManager.DriverConfigs.Impl; +using System.IO; +using System.Runtime.InteropServices; +using System.Threading; +using UniMarc.마크; +using OpenQA.Selenium.Chromium; +using UniMarc.SearchModel; +using System.Runtime.CompilerServices; +using AR; + +namespace BokBonCheck +{ + public class GochangLibSearcher : ILibrarySearcher + { + public string AreaCode { get; set; } = string.Empty; + public string SiteName { get; protected set; } + public string SiteUrl => "https://libsearch.gochang.go.kr:8443/book/bookAdvancedSearch"; + public bool HttpApiMode { get; set; } = false; + + public int No { get; set; } + + private ChromiumDriver _driver; + + public GochangLibSearcher(int no, string areaCode, string areaName) + { + this.No = no; + this.AreaCode = areaCode; + this.SiteName = $"고창군립({areaName})"; + } + + public void StopDriver() + { + if (_driver != null) + { + _driver.Quit(); + _driver.Dispose(); + _driver = null; + } + } + + public async Task StartDriver(bool showdriver = false) + { + if (_driver == null) + { + try + { + if (SeleniumHelper.IsReady == false) await SeleniumHelper.Download(); + _driver = await SeleniumHelper.CreateDriver(ShowBrowser: showdriver); + Console.WriteLine("GochangLibSearcher Driver 초기화 완료"); + } + catch (Exception ex) + { + Console.WriteLine($"GochangLibSearcher Driver 초기화 실패: {ex.Message}"); + throw new InvalidOperationException($"GochangLibSearcher Driver 초기화에 실패했습니다: {ex.Message}", ex); + } + } + } + + virtual protected bool SelectLibrary(WebDriverWait wait) + { + try + { + if (!string.IsNullOrEmpty(AreaCode)) + { + var libSelect = wait.Until(d => d.FindElement(By.Id("MANAGE_CODE"))); + var selectElement = new SelectElement(libSelect); + selectElement.SelectByValue(AreaCode); + Thread.Sleep(300); + Console.WriteLine($"{AreaCode} 도서관으로 선택됨"); + } + else + { + Console.WriteLine("전체 도서관으로 검색"); + } + + return true; + } + catch (Exception ex) + { + Console.WriteLine($"도서관 선택 실패: {ex.Message}"); + return false; + } + } + + public async Task SearchAsync(string searchTerm) + { + var result = new BookSearchResult + { + SiteName = SiteName, + SearchTerm = searchTerm, + SearchTime = DateTime.Now + }; + + try + { + if (_driver == null) + { + await StartDriver(); + } + + var cururl = _driver.Url; + if (cururl.Equals(SiteUrl) == false) + _driver.Navigate().GoToUrl(SiteUrl); + + var wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(15)); + + if (SelectLibrary(wait) == false) + { + result.ErrorMessage = "도서관선택실패"; + result.BookCount = -1; + result.IsSuccess = false; + return result; + } + + try + { + var titleInput = wait.Until(d => d.FindElement(By.Id("title"))); + titleInput.Clear(); + titleInput.SendKeys(searchTerm); + } + catch (Exception ex) + { + result.ErrorMessage = $"검색어입력실패({ex.Message})"; + result.BookCount = -1; + result.IsSuccess = false; + return result; + } + + try + { + var jsExecutor = (IJavaScriptExecutor)_driver; + jsExecutor.ExecuteScript("fn_openBookAdvancedSearch();"); + } + catch (Exception ex) + { + result.ErrorMessage = $"검색실행실패({ex.Message})"; + result.BookCount = -1; + result.IsSuccess = false; + return result; + } + + await WaitForPageChange(new WebDriverWait(_driver, TimeSpan.FromSeconds(15))); + + var resultCount = ExtractBookCount(_driver, searchTerm, out string ermsg); + if (resultCount == -1) + { + result.BookCount = 0; + result.IsSuccess = false; + result.ErrorMessage = ermsg; + } + else + { + result.BookCount = resultCount; + result.IsSuccess = true; + result.ErrorMessage = ermsg; + } + + } + catch (Exception ex) + { + result.IsSuccess = false; + result.ErrorMessage = ex.Message; + result.BookCount = 0; + } + + return result; + } + + private int ExtractBookCount(IWebDriver driver, string searchTerm, out string errmessage) + { + errmessage = string.Empty; + try + { + try + { + var noResultElement = driver.FindElement(By.XPath("//*[contains(text(), '검색된 도서가 없습니다') or contains(text(), '검색결과가 없습니다')]")); + if (noResultElement != null) + { + errmessage = "검색결과없음"; + return 0; + } + } + catch + { + } + + try + { + var resultElement = driver.FindElement(By.CssSelector(".subTapContWrap.on p")); + if (resultElement != null) + { + var resultText = resultElement.Text; + var match = Regex.Match(resultText, @"총\s*(\d+)건", RegexOptions.IgnoreCase); + if (match.Success) + { + if (int.TryParse(match.Groups[1].Value, out int count)) + { + if (count == 0) + { + errmessage = "검색결과없음"; + return 0; + } + errmessage = $"검색성공({count}권)"; + return count; + } + } + } + } + catch (Exception ex) + { + Console.WriteLine($"결과 요소 검색 중 오류: {ex.Message}"); + } + + var pageSource = driver.PageSource; + + if (pageSource.Contains("검색된 도서가 없습니다") || + pageSource.Contains("검색결과가 없습니다") || + pageSource.Contains("검색된 자료가 없습니다")) + { + errmessage = "검색결과없음"; + return 0; + } + + var htmlPatterns = new[] + { + @"]*class=""bluecolor""[^>]*>총\s*(\d+)건", + @"총\s*]*class=""bluecolor""[^>]*>(\d+)건", + @"총\s*(\d+)건" + }; + + foreach (var pattern in htmlPatterns) + { + var match = Regex.Match(pageSource, pattern, RegexOptions.IgnoreCase); + if (match.Success) + { + if (int.TryParse(match.Groups[1].Value, out int count)) + { + if (count == 0) + { + errmessage = "검색결과없음"; + return 0; + } + errmessage = $"검색성공({count}권)"; + return count; + } + } + } + + errmessage = "결과수량을찾을수없음"; + return -1; + + } + catch (Exception ex) + { + errmessage = ex.Message; + return -1; + } + } + + public async Task WaitForPageChange(WebDriverWait wait) + { + try + { + await Task.Delay(500); + + wait.Until(d => + { + var readyState = ((IJavaScriptExecutor)d).ExecuteScript("return document.readyState"); + return readyState.Equals("complete"); + }); + + wait.Until(d => + { + try + { + var pageSource = d.PageSource; + return pageSource.Contains("검색결과입니다") || + pageSource.Contains("총") || + pageSource.Contains("건") || + pageSource.Contains("검색된 도서가 없습니다"); + } + catch + { + return false; + } + }); + + } + catch (Exception ex) + { + await Task.Delay(3000); + Console.WriteLine($"페이지 변경 감지 실패: {ex.Message}"); + } + } + } +} \ No newline at end of file diff --git a/unimarc/unimarc/UniMarc.csproj b/unimarc/unimarc/UniMarc.csproj index 271bf07..7185567 100644 --- a/unimarc/unimarc/UniMarc.csproj +++ b/unimarc/unimarc/UniMarc.csproj @@ -236,6 +236,7 @@ Form + diff --git a/unimarc/unimarc/마크/Check_copyWD.cs b/unimarc/unimarc/마크/Check_copyWD.cs index bf7e7f9..b409359 100644 --- a/unimarc/unimarc/마크/Check_copyWD.cs +++ b/unimarc/unimarc/마크/Check_copyWD.cs @@ -11,6 +11,7 @@ using AR; using UniMarc.SearchModel; using System.Linq; using UniMarc; +using System.Globalization; namespace WindowsFormsApp1.Mac { @@ -28,7 +29,7 @@ namespace WindowsFormsApp1.Mac { get { - return (DateTime.Now <= new DateTime(2025, 09, 30)); + return (DateTime.Now <= new DateTime(2025, 12, 30)); } } @@ -49,7 +50,7 @@ namespace WindowsFormsApp1.Mac _searchService.AddSearcher(new NamguLibrarySearcher(idx++, "#libSW", "효천어울림도서관")); - if (GetDemoRunAuth == true) + { //광주시교육청통합도서관 _searchService.AddSearcher(new KwangjuCityEduLibrarySearcher(idx++, "MD", "중앙도서관")); @@ -405,6 +406,19 @@ namespace WindowsFormsApp1.Mac } + //고창도서관 추가 250903 + + _searchService.AddSearcher(new GochangLibSearcher(idx++, "MA", "고창군립도서관")); + _searchService.AddSearcher(new GochangLibSearcher(idx++, "MB", "선운산작은도서관")); + _searchService.AddSearcher(new GochangLibSearcher(idx++, "MC", "고수해마루작은도서관")); + _searchService.AddSearcher(new GochangLibSearcher(idx++, "MD", "고창군립성호도서관")); + _searchService.AddSearcher(new GochangLibSearcher(idx++, "ME", "대산큰별작은도서관")); + _searchService.AddSearcher(new GochangLibSearcher(idx++, "MF", "무장글샘작은도서관")); + _searchService.AddSearcher(new GochangLibSearcher(idx++, "MG", "글마루작은도서관")); + _searchService.AddSearcher(new GochangLibSearcher(idx++, "MH", "흥덕가온누리작은도서관")); + _searchService.AddSearcher(new GochangLibSearcher(idx++, "MI", "공음참나무골작은도서관")); + + this.tb_SearchTarget.Items.Clear(); // this.tb_SearchTarget.Items.Add("-- 검색대상을 선택하세요 --"); foreach (var item in _searchService.GetAvailableSites().OrderBy(t => t))