diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..178135c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/dist/ diff --git a/MANIFEST.in b/MANIFEST.in index 2a22c69..7b74127 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1,3 @@ -MANIFEST.in +include LICENSE +include README.md +include requirements.txt diff --git a/README.md b/README.md index 1003f5e..be14815 100644 --- a/README.md +++ b/README.md @@ -20,23 +20,40 @@ package is not yet available on PyPI. Stay tuned for updates and the official re ## Installation -The package will be available for installation via pip upon its release. -For now, you can clone the repository and install the package locally. +`pip install kheritage` ## Usage Here's a basic example of how to use the KHeritageAPI to perform a search: ```python -from kheritageapi import ConstructSearch, Seoul - -search = ConstructSearch(city_code=Seoul.JONGNRO) -search.set_result_count(1) -print(search.get_url()) +from kheritageapi.api import Search, ItemDetail, EventSearch +from kheritageapi.models import CityCode, Seoul, HeritageType + +# Search for 15 historic sites in Seoul's Jongno district +search = Search(result_count=15, city_code=CityCode.SEOUL, district_code=Seoul.JONGNRO, canceled=False, + heritage_type=HeritageType.HISTORIC_SITE) +result = search.commit_search() + +# Get detailed information on the first item +detail = ItemDetail(result.items[0]) +detail_info = detail.info() +print(detail_info) + +# Also, you can get images and videos of the item +images = detail.image() +print(images) + +videos = detail.video() +print(videos) + +# Search for events in 2023, December +event_search = EventSearch(2023, 12) +events = event_search.commit_search() +for event in events: + print(event) ``` -Further documentation and examples will be provided upon the release. - ## Contributing Contributions to KHeritageAPI are welcome. If you're interested in contributing, please fork the repository and submit a diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..b2620b8 --- /dev/null +++ b/build.sh @@ -0,0 +1,4 @@ +python3 -m pip install --upgrade build +python3 -m build +python3 -m pip install --upgrade twine +python3 -m twine upload dist/* diff --git a/kheritageapi/__init__.py b/kheritageapi/__init__.py index 387d448..0831758 100644 --- a/kheritageapi/__init__.py +++ b/kheritageapi/__init__.py @@ -1,3 +1,3 @@ -import api -import models -import utils +__version__ = '0.0.5' + +from kheritageapi import * diff --git a/kheritageapi/api.py b/kheritageapi/api.py index bbc59c3..f189574 100644 --- a/kheritageapi/api.py +++ b/kheritageapi/api.py @@ -10,10 +10,9 @@ # (https://joseon.space). This module aims to facilitate efficient and accurate access to Korea's rich cultural # heritage data for developers and researchers globally. # -import xml.etree.ElementTree as ET import requests -from models import * +from .models import * class APIBase: @@ -32,7 +31,7 @@ class Search(APIBase): ENDPOINT = 'SearchKindOpenapiList.do' def __init__(self, heritage_type: HeritageType = None, start_year: int = None, end_year: int = None, - ko_name: str = None, province_code: ProvinceCode = None, city_code: CityCode = None, + ko_name: str = None, city_code: CityCode = None, district_code: DistrictCode = None, linked_number: str = None, canceled: bool = None, result_count: int = 10, page_index: int = 1): super().__init__() @@ -50,10 +49,10 @@ def __init__(self, heritage_type: HeritageType = None, start_year: int = None, e self.params['ccbaCncl'] = 'Y' if canceled else 'N' # 지정해제여부 (Y, N) if heritage_type is not None: # 지정종목별 self.params['ccbaKdcd'] = heritage_type.value - if province_code is not None: - self.params['ccbaCtcd'] = province_code.value if city_code is not None: - self.params['ccbaLcto'] = city_code.value + self.params['ccbaCtcd'] = city_code.value + if district_code is not None: + self.params['ccbaLcto'] = district_code.value def commit_search(self): xml_data = self._get(self.ENDPOINT, params=self.params).text @@ -71,11 +70,11 @@ def set_end_year(self, end_year: int) -> None: def set_ko_name(self, ko_name: str) -> None: self.params['ccbaMnm1'] = ko_name - def set_province(self, province_code: ProvinceCode) -> None: - self.params['ccbaCtcd'] = province_code.value + def set_province(self, city_code: CityCode) -> None: + self.params['ccbaCtcd'] = city_code.value - def set_city(self, city_code: CityCode) -> None: - self.params['ccbaLcto'] = city_code.value + def set_city(self, district_code: DistrictCode) -> None: + self.params['ccbaLcto'] = district_code.value def set_linked_number(self, linked_number: str) -> None: self.params['ccbaCpno'] = linked_number @@ -127,7 +126,7 @@ def __init__(self, year: int, month: int, search_word: str = None, event_type: E def commit_search(self): xml_data = self._get(self.ENDPOINT, params=self.params).text - root = ET.fromstring(xml_data) + root = ElementTree.fromstring(xml_data) # iterate through the items in the XML items = [] @@ -138,9 +137,28 @@ def commit_search(self): return items +# Example Usage if __name__ == '__main__': - search = EventSearch(2023, 4) + # Search for 15 historic sites in Seoul's Jongno district + search = Search(result_count=15, city_code=CityCode.SEOUL, district_code=Seoul.JONGNRO, canceled=False, + heritage_type=HeritageType.HISTORIC_SITE) result = search.commit_search() - for item in result: - print(item) + # Get detailed information on the first item + detail = ItemDetail(result.items[0]) + detail_info = detail.info() + print(detail_info) + + # Also, you can get images and videos of the item + images = detail.image() + print(images) + + videos = detail.video() + print(videos) + + # Search for events in 2023, December + event_search = EventSearch(2023, 12) + events = event_search.commit_search() + for event in events: + print(event) + diff --git a/kheritageapi/models.py b/kheritageapi/models.py index c03b392..b37031a 100644 --- a/kheritageapi/models.py +++ b/kheritageapi/models.py @@ -377,7 +377,7 @@ class EventType(Enum): OTHERS = '06' # 기타행사 -class ProvinceCode(Enum): +class CityCode(Enum): SEOUL = '11' # 서울 BUSAN = '21' # 부산 DAEGU = '22' # 대구 @@ -398,11 +398,11 @@ class ProvinceCode(Enum): NATIONAL = 'ZZ' # 전국일원 -class CityCode(Enum): +class DistrictCode(Enum): pass -class Seoul(CityCode): +class Seoul(DistrictCode): ALL = '00' # 전체 JONGNRO = '11' # 종로구 JUNG = '12' # 중구 @@ -433,7 +433,7 @@ class Seoul(CityCode): SEOUL_WIDE = 'ZZ' # 서울전역 -class Busan(CityCode): +class Busan(DistrictCode): ALL = '00' # 전체 JUNG = '11' # 중구 SEO = '12' # 서구 @@ -454,7 +454,7 @@ class Busan(CityCode): BUSAN_WIDE = 'ZZ' # 부산전역 -class Daegu(CityCode): +class Daegu(DistrictCode): ALL = '00' # 전체 JUNG = '11' # 중구 DONG = '12' # 동구 @@ -468,7 +468,7 @@ class Daegu(CityCode): GUNWI = '32' # 군위군 -class Incheon(CityCode): +class Incheon(DistrictCode): ALL = '00' # 전체 JUNG = '11' # 중구 DONG = '12' # 동구 @@ -483,7 +483,7 @@ class Incheon(CityCode): INCHEON_WIDE = 'ZZ' # 인천전역 -class Gwangju(CityCode): +class Gwangju(DistrictCode): ALL = '00' # 전체 DONG = '11' # 동구 SEO = '12' # 서구 @@ -493,7 +493,7 @@ class Gwangju(CityCode): GWANGJU_WIDE = 'ZZ' # 광주전역 -class Daejeon(CityCode): +class Daejeon(DistrictCode): ALL = '00' # 전체 DONG = '11' # 동구 JUNG = '12' # 중구 @@ -503,7 +503,7 @@ class Daejeon(CityCode): DAEJEON_WIDE = 'ZZ' # 대전전역 -class Ulsan(CityCode): +class Ulsan(DistrictCode): ALL = '00' # 전체 NAM = '01' # 남구 DONG = '02' # 동구 @@ -513,11 +513,11 @@ class Ulsan(CityCode): ULSAN_WIDE = 'ZZ' # 울산전역 -class Sejong(CityCode): +class Sejong(DistrictCode): SEJONG_WIDE = '00' # 세종시전역 -class Gyeonggi(CityCode): +class Gyeonggi(DistrictCode): ALL = '00' # 전체 SUWON = '11' # 수원시 SEONGNAM = '12' # 성남시 @@ -553,7 +553,7 @@ class Gyeonggi(CityCode): GYEONGGI_WIDE = 'ZZ' # 경기전역 -class Gangwon(CityCode): +class Gangwon(DistrictCode): ALL = '00' # 전체 CHUNCHEON = '11' # 춘천시 WONJU = '12' # 원주시 @@ -577,7 +577,7 @@ class Gangwon(CityCode): GANGWON_WIDE = 'ZZ' # 강원전역 -class Chungbuk(CityCode): +class Chungbuk(DistrictCode): ALL = '00' # 전체 CHEONGJU = '20' # 청주시 CHUNGJU = '12' # 충주시 @@ -593,7 +593,7 @@ class Chungbuk(CityCode): CHUNGBUK_WIDE = 'ZZ' # 충북전역 -class Chungnam(CityCode): +class Chungnam(DistrictCode): ALL = '00' # 전체 CHEONAN = '11' # 천안시 GONGJU = '12' # 공주시 @@ -613,7 +613,7 @@ class Chungnam(CityCode): CHUNGNAM_WIDE = 'ZZ' # 충남전역 -class Jeonbuk(CityCode): +class Jeonbuk(DistrictCode): ALL = '00' # 전체 JEONJU = '11' # 전주시 GUNSAN = '12' # 군산시 @@ -632,7 +632,7 @@ class Jeonbuk(CityCode): JEONBUK_WIDE = 'ZZ' # 전북전역 -class Jeonnam(CityCode): +class Jeonnam(DistrictCode): ALL = '00' # 전체 MOKPO = '11' # 목포시 YEOSU = '12' # 여수시 @@ -662,7 +662,7 @@ class Jeonnam(CityCode): JEONNAM_WIDE = 'ZZ' # 전남전역 -class Gyeongbuk(CityCode): +class Gyeongbuk(DistrictCode): ALL = '00' # 전체 POHANG = '11' # 포항시 GYEONGJU = '12' # 경주시 @@ -689,7 +689,7 @@ class Gyeongbuk(CityCode): GYEONGBUK_WIDE = 'ZZ' # 경북전역 -class Gyeongnam(CityCode): +class Gyeongnam(DistrictCode): ALL = '00' # 전체 JINJU = '13' # 진주시 CHANGWON = '50' # 창원시 @@ -713,15 +713,8 @@ class Gyeongnam(CityCode): GYEONGNAM_WIDE = 'ZZ' # 경남전역 -class Jeju(CityCode): +class Jeju(DistrictCode): ALL = '00' # 전체 JEJU_CITY = '01' # 제주시 SEOGWIPO = '02' # 서귀포시 JEJU_WIDE = 'ZZ' # 제주전역 - - -if __name__ == '__main__': - print(HeritageType.TREASURE.value) - print(EventType.NIGHTTIME_HERITAGE.value) - print(ProvinceCode.SEOUL.value) - print(Seoul.JONGNRO.value) diff --git a/pyproject.toml b/pyproject.toml index 21026b8..17b56d2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] -name = "K-Heritage API" -version = "0.0.1" +name = "kheritage" +version = "0.0.5" authors = [ { name="Jay Suh", email="jay@joseon.space" }, ] @@ -17,3 +17,10 @@ classifiers = [ "Homepage" = "https://github.com/SuhJae/KHeritageAPI" "Bug Tracker" = "https://github.com/SuhJae/KHeritageAPI/issues" "Source Code" = "https://github.com/SuhJae/KHeritageAPI" + +[build-system] +requires = ["requests", "setuptools", "wheel"] + +[tool.setuptools.dynamic] + +dependencies = { file = "requirements.txt" } \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 86dabd6..0eb8cae 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -requests~=2.31.0 +requests>=2.31.0 diff --git a/setup.py b/setup.py deleted file mode 100644 index 86a9717..0000000 --- a/setup.py +++ /dev/null @@ -1,8 +0,0 @@ -from setuptools import setup, find_packages - -setup( - packages=find_packages(), - install_requires=[ - 'requests', - ] -)