고창군립도서관 검색기 구현 및 라이선스 기간 연장
- GochangLibSearcher.cs: 고창군립도서관 HTTP API 검색기 추가 - 고창군립도서관 및 산하 9개 분관 검색 대상에 등록 - 라이선스 기간 2025.12.30까지 연장 - 어셈블리 버전 2025.09.03.2030으로 업데이트 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,13 @@
|
|||||||
"permissions": {
|
"permissions": {
|
||||||
"allow": [
|
"allow": [
|
||||||
"Bash(git add:*)",
|
"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": [],
|
"deny": [],
|
||||||
"ask": []
|
"ask": []
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -14,7 +14,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("pofalApi_tmp")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("pofalApi_tmp")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[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.AssemblyProductAttribute("pofalApi_tmp")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("pofalApi_tmp")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("pofalApi_tmp")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
c13c9c2f2e12bc007cbcab6ccdb94397f9d2465a
|
1e22963f41eb10ec8b7d5cf0f11446afcd4c7c64669758c39d9d6d7a2dc5abbf
|
||||||
|
|||||||
Binary file not shown.
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를
|
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를
|
||||||
// 기본값으로 할 수 있습니다.
|
// 기본값으로 할 수 있습니다.
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("2025.08.19.2250")]
|
[assembly: AssemblyVersion("2025.09.03.2030")]
|
||||||
[assembly: AssemblyFileVersion("2025.08.19.2250")]
|
[assembly: AssemblyFileVersion("2025.09.03.2030")]
|
||||||
|
|||||||
303
unimarc/unimarc/SearchModel/GochangLibSearcher.cs
Normal file
303
unimarc/unimarc/SearchModel/GochangLibSearcher.cs
Normal file
@@ -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<BookSearchResult> 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[]
|
||||||
|
{
|
||||||
|
@"<span[^>]*class=""bluecolor""[^>]*>총\s*(\d+)건</span>",
|
||||||
|
@"총\s*<span[^>]*class=""bluecolor""[^>]*>(\d+)</span>건",
|
||||||
|
@"총\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}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -236,6 +236,7 @@
|
|||||||
<Compile Include="SearchModel\DownloadProgressForm.cs">
|
<Compile Include="SearchModel\DownloadProgressForm.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="SearchModel\GochangLibSearcher.cs" />
|
||||||
<Compile Include="SearchModel\GoheungLibSearcher.cs" />
|
<Compile Include="SearchModel\GoheungLibSearcher.cs" />
|
||||||
<Compile Include="SearchModel\GwangjuCityLibSearcher.cs" />
|
<Compile Include="SearchModel\GwangjuCityLibSearcher.cs" />
|
||||||
<Compile Include="SearchModel\GwangjuDongguLibSearcher.cs" />
|
<Compile Include="SearchModel\GwangjuDongguLibSearcher.cs" />
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ using AR;
|
|||||||
using UniMarc.SearchModel;
|
using UniMarc.SearchModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using UniMarc;
|
using UniMarc;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
namespace WindowsFormsApp1.Mac
|
namespace WindowsFormsApp1.Mac
|
||||||
{
|
{
|
||||||
@@ -28,7 +29,7 @@ namespace WindowsFormsApp1.Mac
|
|||||||
{
|
{
|
||||||
get
|
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", "효천어울림도서관"));
|
_searchService.AddSearcher(new NamguLibrarySearcher(idx++, "#libSW", "효천어울림도서관"));
|
||||||
|
|
||||||
|
|
||||||
if (GetDemoRunAuth == true)
|
|
||||||
{
|
{
|
||||||
//광주시교육청통합도서관
|
//광주시교육청통합도서관
|
||||||
_searchService.AddSearcher(new KwangjuCityEduLibrarySearcher(idx++, "MD", "중앙도서관"));
|
_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.Clear();
|
||||||
// this.tb_SearchTarget.Items.Add("-- 검색대상을 선택하세요 --");
|
// this.tb_SearchTarget.Items.Add("-- 검색대상을 선택하세요 --");
|
||||||
foreach (var item in _searchService.GetAvailableSites().OrderBy(t => t))
|
foreach (var item in _searchService.GetAvailableSites().OrderBy(t => t))
|
||||||
|
|||||||
Reference in New Issue
Block a user