Skip to content

Commit

Permalink
chore: Finalized initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
SuhJae committed Dec 10, 2023
1 parent 407dc3f commit 6cce3d7
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 64 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dist/
4 changes: 3 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
MANIFEST.in
include LICENSE
include README.md
include requirements.txt
35 changes: 26 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
python3 -m pip install --upgrade build
python3 -m build
python3 -m pip install --upgrade twine
python3 -m twine upload dist/*
6 changes: 3 additions & 3 deletions kheritageapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import api
import models
import utils
__version__ = '0.0.5'

from kheritageapi import *
46 changes: 32 additions & 14 deletions kheritageapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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__()

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 = []
Expand All @@ -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)

45 changes: 19 additions & 26 deletions kheritageapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ class EventType(Enum):
OTHERS = '06' # 기타행사


class ProvinceCode(Enum):
class CityCode(Enum):
SEOUL = '11' # 서울
BUSAN = '21' # 부산
DAEGU = '22' # 대구
Expand All @@ -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' # 중구
Expand Down Expand Up @@ -433,7 +433,7 @@ class Seoul(CityCode):
SEOUL_WIDE = 'ZZ' # 서울전역


class Busan(CityCode):
class Busan(DistrictCode):
ALL = '00' # 전체
JUNG = '11' # 중구
SEO = '12' # 서구
Expand All @@ -454,7 +454,7 @@ class Busan(CityCode):
BUSAN_WIDE = 'ZZ' # 부산전역


class Daegu(CityCode):
class Daegu(DistrictCode):
ALL = '00' # 전체
JUNG = '11' # 중구
DONG = '12' # 동구
Expand All @@ -468,7 +468,7 @@ class Daegu(CityCode):
GUNWI = '32' # 군위군


class Incheon(CityCode):
class Incheon(DistrictCode):
ALL = '00' # 전체
JUNG = '11' # 중구
DONG = '12' # 동구
Expand All @@ -483,7 +483,7 @@ class Incheon(CityCode):
INCHEON_WIDE = 'ZZ' # 인천전역


class Gwangju(CityCode):
class Gwangju(DistrictCode):
ALL = '00' # 전체
DONG = '11' # 동구
SEO = '12' # 서구
Expand All @@ -493,7 +493,7 @@ class Gwangju(CityCode):
GWANGJU_WIDE = 'ZZ' # 광주전역


class Daejeon(CityCode):
class Daejeon(DistrictCode):
ALL = '00' # 전체
DONG = '11' # 동구
JUNG = '12' # 중구
Expand All @@ -503,7 +503,7 @@ class Daejeon(CityCode):
DAEJEON_WIDE = 'ZZ' # 대전전역


class Ulsan(CityCode):
class Ulsan(DistrictCode):
ALL = '00' # 전체
NAM = '01' # 남구
DONG = '02' # 동구
Expand All @@ -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' # 성남시
Expand Down Expand Up @@ -553,7 +553,7 @@ class Gyeonggi(CityCode):
GYEONGGI_WIDE = 'ZZ' # 경기전역


class Gangwon(CityCode):
class Gangwon(DistrictCode):
ALL = '00' # 전체
CHUNCHEON = '11' # 춘천시
WONJU = '12' # 원주시
Expand All @@ -577,7 +577,7 @@ class Gangwon(CityCode):
GANGWON_WIDE = 'ZZ' # 강원전역


class Chungbuk(CityCode):
class Chungbuk(DistrictCode):
ALL = '00' # 전체
CHEONGJU = '20' # 청주시
CHUNGJU = '12' # 충주시
Expand All @@ -593,7 +593,7 @@ class Chungbuk(CityCode):
CHUNGBUK_WIDE = 'ZZ' # 충북전역


class Chungnam(CityCode):
class Chungnam(DistrictCode):
ALL = '00' # 전체
CHEONAN = '11' # 천안시
GONGJU = '12' # 공주시
Expand All @@ -613,7 +613,7 @@ class Chungnam(CityCode):
CHUNGNAM_WIDE = 'ZZ' # 충남전역


class Jeonbuk(CityCode):
class Jeonbuk(DistrictCode):
ALL = '00' # 전체
JEONJU = '11' # 전주시
GUNSAN = '12' # 군산시
Expand All @@ -632,7 +632,7 @@ class Jeonbuk(CityCode):
JEONBUK_WIDE = 'ZZ' # 전북전역


class Jeonnam(CityCode):
class Jeonnam(DistrictCode):
ALL = '00' # 전체
MOKPO = '11' # 목포시
YEOSU = '12' # 여수시
Expand Down Expand Up @@ -662,7 +662,7 @@ class Jeonnam(CityCode):
JEONNAM_WIDE = 'ZZ' # 전남전역


class Gyeongbuk(CityCode):
class Gyeongbuk(DistrictCode):
ALL = '00' # 전체
POHANG = '11' # 포항시
GYEONGJU = '12' # 경주시
Expand All @@ -689,7 +689,7 @@ class Gyeongbuk(CityCode):
GYEONGBUK_WIDE = 'ZZ' # 경북전역


class Gyeongnam(CityCode):
class Gyeongnam(DistrictCode):
ALL = '00' # 전체
JINJU = '13' # 진주시
CHANGWON = '50' # 창원시
Expand All @@ -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)
11 changes: 9 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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" },
]
Expand All @@ -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" }
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
requests~=2.31.0
requests>=2.31.0
8 changes: 0 additions & 8 deletions setup.py

This file was deleted.

0 comments on commit 6cce3d7

Please sign in to comment.