hossam 0.4.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hossam-0.4.2/LICENSE +18 -0
- hossam-0.4.2/MANIFEST.in +5 -0
- hossam-0.4.2/PKG-INFO +105 -0
- hossam-0.4.2/README.md +62 -0
- hossam-0.4.2/hossam/NotoSansKR-Regular.ttf +0 -0
- hossam-0.4.2/hossam/__init__.py +84 -0
- hossam-0.4.2/hossam/data_loader.py +205 -0
- hossam-0.4.2/hossam/hs_classroom.py +758 -0
- hossam-0.4.2/hossam/hs_gis.py +305 -0
- hossam-0.4.2/hossam/hs_plot.py +2411 -0
- hossam-0.4.2/hossam/hs_prep.py +889 -0
- hossam-0.4.2/hossam/hs_stats.py +2870 -0
- hossam-0.4.2/hossam/hs_timeserise.py +1113 -0
- hossam-0.4.2/hossam/hs_util.py +237 -0
- hossam-0.4.2/hossam/leekh.png +0 -0
- hossam-0.4.2/hossam.egg-info/PKG-INFO +105 -0
- hossam-0.4.2/hossam.egg-info/SOURCES.txt +20 -0
- hossam-0.4.2/hossam.egg-info/dependency_links.txt +1 -0
- hossam-0.4.2/hossam.egg-info/requires.txt +24 -0
- hossam-0.4.2/hossam.egg-info/top_level.txt +1 -0
- hossam-0.4.2/pyproject.toml +59 -0
- hossam-0.4.2/setup.cfg +4 -0
hossam-0.4.2/LICENSE
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Lee Kwang-Ho
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
13
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
14
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
15
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
16
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
17
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
18
|
+
SOFTWARE.
|
hossam-0.4.2/MANIFEST.in
ADDED
hossam-0.4.2/PKG-INFO
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hossam
|
|
3
|
+
Version: 0.4.2
|
|
4
|
+
Summary: Hossam Data Helper
|
|
5
|
+
Author-email: Lee Kwang-Ho <leekh4232@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/leekh4232/hossam-py
|
|
8
|
+
Project-URL: Repository, https://github.com/leekh4232/hossam-py
|
|
9
|
+
Keywords: data,analysis,helper,hossam,tensorflow
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Requires-Python: >=3.11
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: tqdm
|
|
19
|
+
Requires-Dist: tabulate
|
|
20
|
+
Requires-Dist: pandas
|
|
21
|
+
Requires-Dist: matplotlib
|
|
22
|
+
Requires-Dist: seaborn
|
|
23
|
+
Requires-Dist: requests
|
|
24
|
+
Requires-Dist: openpyxl
|
|
25
|
+
Requires-Dist: xlrd
|
|
26
|
+
Requires-Dist: statsmodels
|
|
27
|
+
Requires-Dist: scipy
|
|
28
|
+
Requires-Dist: scikit-learn
|
|
29
|
+
Requires-Dist: pingouin
|
|
30
|
+
Requires-Dist: statannotations
|
|
31
|
+
Requires-Dist: joblib
|
|
32
|
+
Requires-Dist: geopandas
|
|
33
|
+
Requires-Dist: kmodes
|
|
34
|
+
Requires-Dist: pmdarima
|
|
35
|
+
Requires-Dist: prophet
|
|
36
|
+
Requires-Dist: plotly
|
|
37
|
+
Requires-Dist: jenkspy
|
|
38
|
+
Requires-Dist: flask
|
|
39
|
+
Requires-Dist: xgboost
|
|
40
|
+
Requires-Dist: lightgbm
|
|
41
|
+
Requires-Dist: catboost
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
title: π Hossam Data Helper
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
# π Hossam Data Helper
|
|
49
|
+
|
|
50
|
+
[](https://www.python.org/downloads/)
|
|
51
|
+
[](https://opensource.org/licenses/MIT)
|
|
52
|
+
[](https://pypi.org/project/hossam/)
|
|
53
|
+
[](https://py.hossam.kr)
|
|
54
|
+
|
|
55
|
+
**Hossam**μ λ°μ΄ν° λΆμ, μκ°ν, ν΅κ³ μ²λ¦¬λ₯Ό μν μ’
ν© ν¬νΌ λΌμ΄λΈλ¬λ¦¬μ
λλ€.
|
|
56
|
+
|
|
57
|
+
μμ΄ν°μ(ITWILL)μμ μ§ν μ€μΈ λ¨Έμ λ¬λ λ° λ°μ΄ν° λΆμ μμ
μ μν΄ κ°λ°λμμΌλ©°, μ΄κ΄νΈ κ°μ¬μ κ°μμμ νμ©λ©λλ€.
|
|
58
|
+
|
|
59
|
+
## β¨ μ£Όμ νΉμ§
|
|
60
|
+
|
|
61
|
+
- π **νλΆν μκ°ν**: 25+ μκ°ν ν¨μ (Seaborn/Matplotlib κΈ°λ°)
|
|
62
|
+
- π― **ν΅κ³ λΆμ**: νκ·, λΆλ₯, μκ³μ΄ λΆμ λꡬ
|
|
63
|
+
- π¦ **μν λ°μ΄ν°**: νμ΅μ© λ°μ΄ν°μ
μ¦μ λ‘λ
|
|
64
|
+
- π§ **λ°μ΄ν° μ μ²λ¦¬**: κ²°μΈ‘μΉ μ²λ¦¬, μ΄μμΉ νμ§, μ€μΌμΌλ§
|
|
65
|
+
- π€ **MCP μλ²**: VSCode/Copilotκ³Ό ν΅ν© κ°λ₯ν Model Context Protocol μ§μ
|
|
66
|
+
- π **κ΅μ‘μ© μ΅μ ν**: λ°μ΄ν° λΆμ κ΅μ‘μ νΉνλ μ€κ³
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
## π¦ μ€μΉ
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install hossam
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**μꡬμ¬ν**: Python 3.8 μ΄μ
|
|
76
|
+
|
|
77
|
+
## π μ 체 λ¬Έμ
|
|
78
|
+
|
|
79
|
+
**μμ ν API λ¬Έμμ κ°μ΄λλ [py.hossam.kr](https://py.hossam.kr)μμ νμΈνμΈμ.**
|
|
80
|
+
|
|
81
|
+
### μ£Όμ λͺ¨λ
|
|
82
|
+
|
|
83
|
+
- **hs_plot**: 25+ μκ°ν ν¨μ (μ κ·Έλν, μ°μ λ, νμ€ν κ·Έλ¨, λ°μ€νλ‘―, ννΈλ§΅ λ±)
|
|
84
|
+
- **hs_stats**: νκ·/λΆλ₯ λΆμ, κ΅μ°¨κ²μ¦, μ κ·μ± κ²μ , μκ΄λΆμ λ±
|
|
85
|
+
- **hs_prep**: κ²°μΈ‘μΉ μ²λ¦¬, μ΄μμΉ νμ§, μ€μΌμΌλ§, μΈμ½λ©
|
|
86
|
+
- **hs_gis**: GIS λ°μ΄ν° λ‘λ λ° μκ°ν (λνλ―Όκ΅ μ§λ μ§μ)
|
|
87
|
+
- **hs_classroom**: νμ΅μ© μ΄μ§λΆλ₯, λ€μ€λΆλ₯, νκ· λ°μ΄ν° μμ±
|
|
88
|
+
- **hs_util**: μμ ν
μ΄λΈ μΆλ ₯, 그리λ μμΉ λ±
|
|
89
|
+
|
|
90
|
+
μμΈν μ¬μ©λ²μ [API λ¬Έμ](https://py.hossam.kr/api/hossam/)λ₯Ό μ°Έκ³ νμΈμ.
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
## π λΌμ΄μ μ€
|
|
94
|
+
|
|
95
|
+
μ΄ νλ‘μ νΈλ MIT λΌμ΄μ μ€λ₯Ό λ°λ¦
λλ€. μμ λ‘κ² μ¬μ©, μμ , λ°°ν¬ν μ μμ΅λλ€.
|
|
96
|
+
|
|
97
|
+
## π λ§ν¬
|
|
98
|
+
|
|
99
|
+
- **λ¬Έμ**: [py.hossam.kr](https://py.hossam.kr)
|
|
100
|
+
- **PyPI**: [pypi.org/project/hossam](https://pypi.org/project/hossam/)
|
|
101
|
+
- **κ°μ¬**: μ΄κ΄νΈ (ITWILL λ¨Έμ λ¬λ λ° λ°μ΄ν° λΆμ)
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
{% include 'HOSSAM_API.md' %}
|
hossam-0.4.2/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: π Hossam Data Helper
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# π Hossam Data Helper
|
|
6
|
+
|
|
7
|
+
[](https://www.python.org/downloads/)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
[](https://pypi.org/project/hossam/)
|
|
10
|
+
[](https://py.hossam.kr)
|
|
11
|
+
|
|
12
|
+
**Hossam**μ λ°μ΄ν° λΆμ, μκ°ν, ν΅κ³ μ²λ¦¬λ₯Ό μν μ’
ν© ν¬νΌ λΌμ΄λΈλ¬λ¦¬μ
λλ€.
|
|
13
|
+
|
|
14
|
+
μμ΄ν°μ(ITWILL)μμ μ§ν μ€μΈ λ¨Έμ λ¬λ λ° λ°μ΄ν° λΆμ μμ
μ μν΄ κ°λ°λμμΌλ©°, μ΄κ΄νΈ κ°μ¬μ κ°μμμ νμ©λ©λλ€.
|
|
15
|
+
|
|
16
|
+
## β¨ μ£Όμ νΉμ§
|
|
17
|
+
|
|
18
|
+
- π **νλΆν μκ°ν**: 25+ μκ°ν ν¨μ (Seaborn/Matplotlib κΈ°λ°)
|
|
19
|
+
- π― **ν΅κ³ λΆμ**: νκ·, λΆλ₯, μκ³μ΄ λΆμ λꡬ
|
|
20
|
+
- π¦ **μν λ°μ΄ν°**: νμ΅μ© λ°μ΄ν°μ
μ¦μ λ‘λ
|
|
21
|
+
- π§ **λ°μ΄ν° μ μ²λ¦¬**: κ²°μΈ‘μΉ μ²λ¦¬, μ΄μμΉ νμ§, μ€μΌμΌλ§
|
|
22
|
+
- π€ **MCP μλ²**: VSCode/Copilotκ³Ό ν΅ν© κ°λ₯ν Model Context Protocol μ§μ
|
|
23
|
+
- π **κ΅μ‘μ© μ΅μ ν**: λ°μ΄ν° λΆμ κ΅μ‘μ νΉνλ μ€κ³
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## π¦ μ€μΉ
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install hossam
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**μꡬμ¬ν**: Python 3.8 μ΄μ
|
|
33
|
+
|
|
34
|
+
## π μ 체 λ¬Έμ
|
|
35
|
+
|
|
36
|
+
**μμ ν API λ¬Έμμ κ°μ΄λλ [py.hossam.kr](https://py.hossam.kr)μμ νμΈνμΈμ.**
|
|
37
|
+
|
|
38
|
+
### μ£Όμ λͺ¨λ
|
|
39
|
+
|
|
40
|
+
- **hs_plot**: 25+ μκ°ν ν¨μ (μ κ·Έλν, μ°μ λ, νμ€ν κ·Έλ¨, λ°μ€νλ‘―, ννΈλ§΅ λ±)
|
|
41
|
+
- **hs_stats**: νκ·/λΆλ₯ λΆμ, κ΅μ°¨κ²μ¦, μ κ·μ± κ²μ , μκ΄λΆμ λ±
|
|
42
|
+
- **hs_prep**: κ²°μΈ‘μΉ μ²λ¦¬, μ΄μμΉ νμ§, μ€μΌμΌλ§, μΈμ½λ©
|
|
43
|
+
- **hs_gis**: GIS λ°μ΄ν° λ‘λ λ° μκ°ν (λνλ―Όκ΅ μ§λ μ§μ)
|
|
44
|
+
- **hs_classroom**: νμ΅μ© μ΄μ§λΆλ₯, λ€μ€λΆλ₯, νκ· λ°μ΄ν° μμ±
|
|
45
|
+
- **hs_util**: μμ ν
μ΄λΈ μΆλ ₯, 그리λ μμΉ λ±
|
|
46
|
+
|
|
47
|
+
μμΈν μ¬μ©λ²μ [API λ¬Έμ](https://py.hossam.kr/api/hossam/)λ₯Ό μ°Έκ³ νμΈμ.
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
## π λΌμ΄μ μ€
|
|
51
|
+
|
|
52
|
+
μ΄ νλ‘μ νΈλ MIT λΌμ΄μ μ€λ₯Ό λ°λ¦
λλ€. μμ λ‘κ² μ¬μ©, μμ , λ°°ν¬ν μ μμ΅λλ€.
|
|
53
|
+
|
|
54
|
+
## π λ§ν¬
|
|
55
|
+
|
|
56
|
+
- **λ¬Έμ**: [py.hossam.kr](https://py.hossam.kr)
|
|
57
|
+
- **PyPI**: [pypi.org/project/hossam](https://pypi.org/project/hossam/)
|
|
58
|
+
- **κ°μ¬**: μ΄κ΄νΈ (ITWILL λ¨Έμ λ¬λ λ° λ°μ΄ν° λΆμ)
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
{% include 'HOSSAM_API.md' %}
|
|
Binary file
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# submodules
|
|
2
|
+
from . import hs_classroom
|
|
3
|
+
from . import hs_gis
|
|
4
|
+
from . import hs_plot
|
|
5
|
+
from . import hs_prep
|
|
6
|
+
from . import hs_stats
|
|
7
|
+
from . import hs_timeserise
|
|
8
|
+
from . import hs_util
|
|
9
|
+
from .data_loader import load_data, load_info
|
|
10
|
+
|
|
11
|
+
# py-modules
|
|
12
|
+
import sys
|
|
13
|
+
import warnings
|
|
14
|
+
from matplotlib import pyplot as plt
|
|
15
|
+
from matplotlib import font_manager as fm
|
|
16
|
+
from importlib.resources import files, as_file
|
|
17
|
+
from importlib.metadata import version
|
|
18
|
+
|
|
19
|
+
try:
|
|
20
|
+
__version__ = version("hossam")
|
|
21
|
+
except Exception:
|
|
22
|
+
__version__ = "develop"
|
|
23
|
+
|
|
24
|
+
__all__ = ["load_data", "load_info", "hs_classroom", "hs_gis", "hs_plot", "hs_prep", "hs_stats", "hs_timeserise", "hs_util"]
|
|
25
|
+
|
|
26
|
+
# λ΄λΆ λͺ¨λμμ hs_figλ₯Ό μ¬μ©ν λλ μλμ κ°μ΄ import νμΈμ.
|
|
27
|
+
# from hossam import hs_fig
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _init_korean_font():
|
|
31
|
+
"""
|
|
32
|
+
ν¨ν€μ§μ ν¬ν¨λ νκΈ ν°νΈλ₯Ό κΈ°λ³Έ ν°νΈλ‘ μ€μ ν©λλ€.
|
|
33
|
+
"""
|
|
34
|
+
font_file = "NotoSansKR-Regular.ttf"
|
|
35
|
+
try:
|
|
36
|
+
# ν¨ν€μ§ 리μμ€μμ ν°νΈ νμΌ κ²½λ‘ ν보
|
|
37
|
+
with as_file(files("hossam") / font_file) as font_path:
|
|
38
|
+
fm.fontManager.addfont(str(font_path))
|
|
39
|
+
fprop = fm.FontProperties(fname=str(font_path))
|
|
40
|
+
fname = fprop.get_name()
|
|
41
|
+
|
|
42
|
+
plt.rcParams.update({
|
|
43
|
+
"font.family": fname,
|
|
44
|
+
"font.size": hs_plot.config.font_size,
|
|
45
|
+
"font.weight": hs_plot.config.font_weight,
|
|
46
|
+
"axes.unicode_minus": False,
|
|
47
|
+
"text.antialiased": True,
|
|
48
|
+
"lines.antialiased": True,
|
|
49
|
+
"patch.antialiased": True,
|
|
50
|
+
"figure.dpi": hs_plot.config.dpi,
|
|
51
|
+
"savefig.dpi": hs_plot.config.dpi * 2,
|
|
52
|
+
"text.hinting": "auto",
|
|
53
|
+
"text.hinting_factor": 8,
|
|
54
|
+
"pdf.fonttype": 42,
|
|
55
|
+
"ps.fonttype": 42,
|
|
56
|
+
})
|
|
57
|
+
if sys.stdout.isatty():
|
|
58
|
+
print(
|
|
59
|
+
"\nβ
μκ°νλ₯Ό μν νκΈ κΈκΌ΄(NotoSansKR-Regular)μ΄ μλ μ μ©λμμ΅λλ€."
|
|
60
|
+
)
|
|
61
|
+
return
|
|
62
|
+
except Exception as e:
|
|
63
|
+
warnings.warn(f"\nνκΈ ν°νΈ μ΄κΈ°ν: ν¨ν€μ§ ν°νΈ μ¬μ© μ€ν¨ ({e}).")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _init():
|
|
67
|
+
|
|
68
|
+
# μλ΄ λ©μμ§ (λΈλ¦Ώ 리μ€νΈ)
|
|
69
|
+
messages = [
|
|
70
|
+
"π¦ μμ΄ν°μ μ΄κ΄νΈ κ°μ¬κ° μ μν λΌμ΄λΈλ¬λ¦¬λ₯Ό μ¬μ©μ€μ
λλ€.",
|
|
71
|
+
"π μμΈν μ¬μ© λ°©λ²μ https://py.hossam.kr μ μ°Έκ³ νμΈμ.",
|
|
72
|
+
"π§ Email: leekh4232@gmail.com",
|
|
73
|
+
"π¬ Youtube: https://www.youtube.com/@hossam-codingclub",
|
|
74
|
+
"π Blog: https://blog.hossam.kr/",
|
|
75
|
+
f"π Version: {__version__}",
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
for msg in messages:
|
|
79
|
+
print(f"{msg}")
|
|
80
|
+
|
|
81
|
+
_init_korean_font()
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
_init()
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# -------------------------------------------------------------
|
|
3
|
+
|
|
4
|
+
import requests
|
|
5
|
+
import json
|
|
6
|
+
from os.path import join, exists
|
|
7
|
+
from io import BytesIO
|
|
8
|
+
from pandas import DataFrame, read_csv, read_excel
|
|
9
|
+
from typing import Optional
|
|
10
|
+
from typing import Optional
|
|
11
|
+
|
|
12
|
+
BASE_URL = "https://data.hossam.kr"
|
|
13
|
+
|
|
14
|
+
# -------------------------------------------------------------
|
|
15
|
+
def __get_df(path: str, index_col=None) -> DataFrame:
|
|
16
|
+
p = path.rfind(".")
|
|
17
|
+
exec = path[p+1:].lower()
|
|
18
|
+
|
|
19
|
+
if exec == 'xlsx':
|
|
20
|
+
# If path is a remote URL, fetch the file once and reuse the bytes
|
|
21
|
+
if path.lower().startswith(('http://', 'https://')):
|
|
22
|
+
path = path.replace("\\", "/")
|
|
23
|
+
with requests.Session() as session:
|
|
24
|
+
r = session.get(path)
|
|
25
|
+
|
|
26
|
+
if r.status_code != 200:
|
|
27
|
+
raise Exception(f"HTTP {r.status_code} Error - {r.reason} > {path}")
|
|
28
|
+
|
|
29
|
+
data_bytes = r.content
|
|
30
|
+
|
|
31
|
+
# Use separate BytesIO objects for each read to avoid pointer/stream issues
|
|
32
|
+
df = read_excel(BytesIO(data_bytes), index_col=index_col)
|
|
33
|
+
|
|
34
|
+
try:
|
|
35
|
+
info = read_excel(BytesIO(data_bytes), sheet_name='metadata', index_col=0)
|
|
36
|
+
#print("\033[94m[metadata]\033[0m")
|
|
37
|
+
print()
|
|
38
|
+
from .util import hs_pretty_table
|
|
39
|
+
hs_pretty_table(info)
|
|
40
|
+
print()
|
|
41
|
+
except Exception:
|
|
42
|
+
#print(f"\033[91m[!] Cannot read metadata\033[0m")
|
|
43
|
+
pass
|
|
44
|
+
else:
|
|
45
|
+
df = read_excel(path, index_col=index_col)
|
|
46
|
+
|
|
47
|
+
try:
|
|
48
|
+
info = read_excel(path, sheet_name='metadata', index_col=0)
|
|
49
|
+
#print("\033[94m[metadata]\033[0m")
|
|
50
|
+
print()
|
|
51
|
+
from .util import hs_pretty_table
|
|
52
|
+
hs_pretty_table(info)
|
|
53
|
+
print()
|
|
54
|
+
except:
|
|
55
|
+
#print(f"\033[91m[!] Cannot read metadata\033[0m")
|
|
56
|
+
pass
|
|
57
|
+
else:
|
|
58
|
+
df = read_csv(path, index_col=index_col)
|
|
59
|
+
|
|
60
|
+
return df
|
|
61
|
+
|
|
62
|
+
# -------------------------------------------------------------
|
|
63
|
+
def __get_data_url(key: str, local: str = None) -> str:
|
|
64
|
+
global BASE_URL
|
|
65
|
+
|
|
66
|
+
path = None
|
|
67
|
+
|
|
68
|
+
if not local:
|
|
69
|
+
data_path = join(BASE_URL, "metadata.json").replace("\\", "/")
|
|
70
|
+
|
|
71
|
+
with requests.Session() as session:
|
|
72
|
+
r = session.get(data_path)
|
|
73
|
+
|
|
74
|
+
if r.status_code != 200:
|
|
75
|
+
raise Exception("[%d Error] %s" % (r.status_code, r.reason))
|
|
76
|
+
|
|
77
|
+
my_dict = r.json()
|
|
78
|
+
info = my_dict.get(key.lower())
|
|
79
|
+
|
|
80
|
+
if not info:
|
|
81
|
+
raise FileNotFoundError("%sλ μ‘΄μ¬νμ§ μλ λ°μ΄ν°μ λν μμ²μ
λλ€." % key)
|
|
82
|
+
|
|
83
|
+
path = join(BASE_URL, info['url'])
|
|
84
|
+
else:
|
|
85
|
+
data_path = join(local, "metadata.json")
|
|
86
|
+
|
|
87
|
+
if not exists(data_path):
|
|
88
|
+
raise FileNotFoundError("μ‘΄μ¬νμ§ μλ λ°μ΄ν°μ λν μμ²μ
λλ€.")
|
|
89
|
+
|
|
90
|
+
with open(data_path, "r", encoding="utf-8") as f:
|
|
91
|
+
my_dict = json.loads(f.read())
|
|
92
|
+
|
|
93
|
+
info = my_dict.get(key.lower())
|
|
94
|
+
path = join(local, info['url'])
|
|
95
|
+
|
|
96
|
+
return path, info.get('desc'), info.get('index')
|
|
97
|
+
|
|
98
|
+
# -------------------------------------------------------------
|
|
99
|
+
def load_info(search: str = None, local: str = None) -> DataFrame:
|
|
100
|
+
"""λ©νλ°μ΄ν°μμ μ¬μ© κ°λ₯ν λ°μ΄ν°μ
μ 보λ₯Ό λ‘λνλ€.
|
|
101
|
+
|
|
102
|
+
Args:
|
|
103
|
+
search (str, optional): μ΄λ¦ νν° λ¬Έμμ΄. ν¬ν¨νλ νλͺ©λ§ λ°ν.
|
|
104
|
+
local (str, optional): λ‘컬 λ©νλ°μ΄ν° κ²½λ‘. Noneμ΄λ©΄ μ격(BASE_URL) μ¬μ©.
|
|
105
|
+
|
|
106
|
+
Returns:
|
|
107
|
+
DataFrame: name, chapter, desc, url 컬λΌμ κ°λ ν
μ΄λΈ
|
|
108
|
+
|
|
109
|
+
Examples:
|
|
110
|
+
```python
|
|
111
|
+
from hossam import *
|
|
112
|
+
info = load_info()
|
|
113
|
+
list(info.columns) #['name', 'chapter', 'desc', 'url']
|
|
114
|
+
```
|
|
115
|
+
"""
|
|
116
|
+
global BASE_URL
|
|
117
|
+
|
|
118
|
+
path = None
|
|
119
|
+
|
|
120
|
+
if not local:
|
|
121
|
+
data_path = join(BASE_URL, "metadata.json").replace("\\", "/")
|
|
122
|
+
|
|
123
|
+
with requests.Session() as session:
|
|
124
|
+
r = session.get(data_path)
|
|
125
|
+
|
|
126
|
+
if r.status_code != 200:
|
|
127
|
+
raise Exception("[%d Error] %s ::: %s" % (r.status_code, r.reason, data_path))
|
|
128
|
+
|
|
129
|
+
my_dict = r.json()
|
|
130
|
+
else:
|
|
131
|
+
data_path = join(local, "metadata.json")
|
|
132
|
+
|
|
133
|
+
if not exists(data_path):
|
|
134
|
+
raise FileNotFoundError("μ‘΄μ¬νμ§ μλ λ°μ΄ν°μ λν μμ²μ
λλ€.")
|
|
135
|
+
|
|
136
|
+
with open(data_path, "r", encoding="utf-8") as f:
|
|
137
|
+
my_dict = json.loads(f.read())
|
|
138
|
+
|
|
139
|
+
my_data = []
|
|
140
|
+
for key in my_dict:
|
|
141
|
+
if 'index' in my_dict[key]:
|
|
142
|
+
del my_dict[key]['index']
|
|
143
|
+
|
|
144
|
+
my_dict[key]['url'] = "%s/%s" % (BASE_URL, my_dict[key]['url'])
|
|
145
|
+
my_dict[key]['name'] = key
|
|
146
|
+
|
|
147
|
+
if 'chapter' in my_dict[key]:
|
|
148
|
+
my_dict[key]['chapter'] = ", ".join(my_dict[key]['chapter'])
|
|
149
|
+
else:
|
|
150
|
+
my_dict[key]['chapter'] = '곡ν΅'
|
|
151
|
+
|
|
152
|
+
my_data.append(my_dict[key])
|
|
153
|
+
|
|
154
|
+
my_df = DataFrame(my_data)
|
|
155
|
+
my_df2 = my_df.reindex(columns=['name', 'chapter', 'desc', 'url'])
|
|
156
|
+
|
|
157
|
+
if search:
|
|
158
|
+
my_df2 = my_df2[my_df2['name'].str.contains(search.lower())]
|
|
159
|
+
|
|
160
|
+
return my_df2
|
|
161
|
+
|
|
162
|
+
# -------------------------------------------------------------
|
|
163
|
+
def load_data(key: str, local: str = None) -> Optional[DataFrame]:
|
|
164
|
+
"""ν€λ‘ μ§μ λ λ°μ΄ν°μ
μ λ‘λνλ€.
|
|
165
|
+
|
|
166
|
+
Args:
|
|
167
|
+
key (str): λ©νλ°μ΄ν°μ μ μλ λ°μ΄ν° μλ³μ(νμΌλͺ
λλ λ³μΉ)
|
|
168
|
+
local (str, optional): λ‘컬 λ©νλ°μ΄ν° κ²½λ‘. Noneμ΄λ©΄ μ격(BASE_URL) μ¬μ©.
|
|
169
|
+
|
|
170
|
+
Returns:
|
|
171
|
+
DataFrame | None: μ±κ³΅ μ λ°μ΄ν°νλ μ, μ€ν¨ μ None
|
|
172
|
+
|
|
173
|
+
Examples:
|
|
174
|
+
```python
|
|
175
|
+
from hossam import *
|
|
176
|
+
df = load_data('AD_SALES') # λ©νλ°μ΄ν°μ ν΄λΉ ν€κ° μμ΄μΌ ν¨
|
|
177
|
+
```
|
|
178
|
+
"""
|
|
179
|
+
index = None
|
|
180
|
+
try:
|
|
181
|
+
url, desc, index = __get_data_url(key, local=local)
|
|
182
|
+
except Exception as e:
|
|
183
|
+
try:
|
|
184
|
+
print(f"\033[91m{str(e)}\033[0m")
|
|
185
|
+
except Exception:
|
|
186
|
+
print(e)
|
|
187
|
+
return
|
|
188
|
+
|
|
189
|
+
#print("\033[94m[data]\033[0m", url.replace("\\", "/"))
|
|
190
|
+
#print("\033[94m[desc]\033[0m", desc)
|
|
191
|
+
print(f"\033[94m{desc}\033[0m")
|
|
192
|
+
|
|
193
|
+
df = None
|
|
194
|
+
|
|
195
|
+
try:
|
|
196
|
+
df = __get_df(url, index_col=index)
|
|
197
|
+
except Exception as e:
|
|
198
|
+
try:
|
|
199
|
+
print(f"\033[91m{str(e)}\033[0m")
|
|
200
|
+
except Exception:
|
|
201
|
+
print(e)
|
|
202
|
+
return
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
return df
|